Skip to content

Commit b60b37b

Browse files
committed
[ticket/17135] Address review issues but constants
PHPBB-17135
1 parent 99969c9 commit b60b37b

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

messenger/method/base.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public function __construct(
117117
service_collection $twig_extensions_collection,
118118
lexer $twig_lexer,
119119
user $user,
120-
$phpbb_root_path,
121-
$template_cache_path,
120+
string $phpbb_root_path,
121+
string $template_cache_path,
122122
?manager $ext_manager = null,
123123
?log_interface $log = null
124124
)
@@ -154,6 +154,8 @@ abstract public function is_enabled(): bool;
154154
/**
155155
* Sets the use of messenger queue flag
156156
*
157+
* @param bool $use_queue Flag indicating if cached queue to be used
158+
*
157159
* @return void
158160
*/
159161
public function set_use_queue(bool $use_queue = true): void
@@ -426,7 +428,6 @@ public function save_queue(): void
426428
if ($this->use_queue && !empty($this->queue))
427429
{
428430
$this->queue->save();
429-
return;
430431
}
431432
}
432433

messenger/method/email.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ public function init(): void
110110
}
111111

112112
/**
113-
* Sets the use of messenger queue flag
114-
*
115-
* @return void
113+
* {@inheritdoc}
116114
*/
117115
public function set_use_queue(bool $use_queue = true): void
118116
{
@@ -124,7 +122,7 @@ public function set_use_queue(bool $use_queue = true): void
124122
*/
125123
public function set_addresses(array $user_row): void
126124
{
127-
if (isset($user_row['user_email']) && $user_row['user_email'])
125+
if (!empty($user_row['user_email']))
128126
{
129127
$this->to($user_row['user_email'], $user_row['username'] ?: '');
130128
}
@@ -295,8 +293,8 @@ protected function build_headers(): void
295293
'Return-Path' => new Address($this->config['board_email']),
296294
'Sender' => new Address($this->config['board_email']),
297295
'X-MSMail-Priority' => self::PRIORITY_MAP[$this->mail_priority],
298-
'X-Mailer' => 'phpBB3',
299-
'X-MimeOLE' => 'phpBB3',
296+
'X-Mailer' => 'phpBB',
297+
'X-MimeOLE' => 'phpBB',
300298
'X-phpBB-Origin' => 'phpbb://' . str_replace(['http://', 'https://'], ['', ''], generate_board_url()),
301299
];
302300

@@ -472,20 +470,23 @@ public function send(): bool
472470
$this->email->subject($this->subject);
473471
$this->email->text($this->msg);
474472

473+
$break = false;
475474
$subject = $this->subject;
476475
$msg = $this->msg;
477476
$email = $this->email;
478477
/**
479478
* Event to send message via external transport
480479
*
481480
* @event core.notification_message_email
481+
* @var bool break Flag indicating if the function return after hook
482482
* @var string subject The message subject
483483
* @var string msg The message text
484484
* @var string email The Symfony Email object
485485
* @since 3.2.4-RC1
486-
* @changed 4.0.0-a1 Added vars: email. Removed vars: addresses, break
486+
* @changed 4.0.0-a1 Added vars: email. Removed vars: addresses
487487
*/
488488
$vars = [
489+
'break',
489490
'subject',
490491
'msg',
491492
'email',
@@ -495,6 +496,11 @@ public function send(): bool
495496

496497
$this->build_headers();
497498

499+
if ($break)
500+
{
501+
return true;
502+
}
503+
498504
// Send message ...
499505
if (!$this->use_queue)
500506
{

messenger/method/jabber.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function ssl(bool $use_ssl = false): self
191191
*/
192192
public function port(int $port = 5222): self
193193
{
194-
$this->port = ($port) ? $port : 5222;
194+
$this->port = ($port > 0) ? $port : 5222;
195195

196196
// Change port if we use SSL
197197
if ($this->port == 5222 && $this->use_ssl)
@@ -210,14 +210,14 @@ public function port(int $port = 5222): self
210210
*/
211211
public function username(string $username = ''): self
212212
{
213-
if (strpos($username, '@') === false)
213+
if (str_contains($username, '@'))
214214
{
215-
$this->username = $username;
215+
$this->jid = explode('@', $username, 2);
216+
$this->username = $this->jid[0];
216217
}
217218
else
218219
{
219-
$this->jid = explode('@', $username, 2);
220-
$this->username = $this->jid[0];
220+
$this->username = $username;
221221
}
222222

223223
return $this;
@@ -232,7 +232,7 @@ public function username(string $username = ''): self
232232
*/
233233
public function server(string $server = ''): self
234234
{
235-
$this->connect_server = ($server) ? $server : 'localhost';
235+
$this->connect_server = $server ?: 'localhost';
236236
$this->server = $this->jid[1] ?? $this->connect_server;
237237

238238
return $this;
@@ -407,7 +407,7 @@ public function to(string $address, string $realname = ''): void
407407
}
408408

409409
/**
410-
* {@inheritDoc}
410+
* Resets all the data (address, template file, etc) to default
411411
*/
412412
public function reset(): void
413413
{
@@ -663,7 +663,7 @@ public function listen(int $timeout = 10, bool $wait = false): bool|array
663663
}
664664

665665
/**
666-
* Initiates account registration (based on data used for contructor)
666+
* Initiates account registration (based on data used for constructor)
667667
*
668668
* @return bool|null
669669
*/
@@ -714,7 +714,7 @@ function send_presence(string $message = '', string $type = '', bool $unavailabl
714714
*/
715715
function response(array $xml): bool
716716
{
717-
if (!is_array($xml) || !count($xml))
717+
if (!count($xml))
718718
{
719719
return false;
720720
}

notification/method/messenger_base.php

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ protected function notify_using_messenger($notify_method, $template_dir_prefix =
112112
continue;
113113
}
114114

115-
/** @psalm-suppress InvalidTemplateParam */
116115
$messenger_collection_iterator = $this->messenger->getIterator();
117116
foreach ($messenger_collection_iterator as $messenger_method)
118117
{

template/twig/extension.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
namespace phpbb\template\twig;
1515

1616
use Twig\Error\RuntimeError;
17+
use Twig\Extension\CoreExtension;
18+
use Twig\Extension\EscaperExtension;
19+
use Twig\Runtime\EscaperRuntime;
1720

1821
class extension extends \Twig\Extension\AbstractExtension
1922
{
@@ -164,8 +167,7 @@ public function loop_subset(\Twig\Environment $env, $item, $start, $end = null,
164167
// We always include the last element (this was the past design)
165168
$end = ($end == -1 || $end === null) ? null : $end + 1;
166169

167-
/** @psalm-suppress UndefinedFunction */
168-
return twig_slice($env, $item, $start, $end, $preserveKeys);
170+
return CoreExtension::slice($env->getCharset(), $item, $start, $end, $preserveKeys);
169171
}
170172

171173
/**
@@ -214,8 +216,7 @@ public function lang_js(): string
214216
{
215217
$args = func_get_args();
216218

217-
/** @psalm-suppress UndefinedFunction */
218-
return twig_escape_filter($this->environment, call_user_func_array([$this, 'lang'], $args), 'js');
219+
return $this->environment->getRuntime(EscaperRuntime::class)->escape(call_user_func_array([$this, 'lang'], $args), 'js');
219220
}
220221

221222
/**

0 commit comments

Comments
 (0)