Skip to content

Commit 4e653f4

Browse files
committed
[ticket/17281] Update psalm config and fix issues
PHPBB3-17281
1 parent 3533171 commit 4e653f4

40 files changed

+103
-80
lines changed

attachment/upload.php

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ public function upload($form_name, $forum_id, $local = false, $local_storage = '
219219
$this->storage->delete($thumbnail_file);
220220
}
221221

222+
/** @psalm-suppress NoValue */
222223
$this->file_data['error'] = array_merge($this->file_data['error'], $this->file->error);
223224
$this->file_data['post_attach'] = false;
224225

avatar/manager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function get_enabled_drivers()
190190
* @param array $row User data or group data
191191
* @param string $prefix Prefix of data keys (e.g. user), should not include the trailing underscore
192192
*
193-
* @return array User or group data with keys that have been
193+
* @return array{string, string} User or group data with keys that have been
194194
* stripped from the preceding "user_" or "group_"
195195
* Also the group id is prefixed with g, when the prefix group is removed.
196196
*/
@@ -202,7 +202,7 @@ public static function clean_row($row, $prefix = '')
202202
return self::$default_row;
203203
}
204204

205-
$output = array();
205+
$output = [];
206206
foreach ($row as $key => $value)
207207
{
208208
$key = preg_replace("#^(?:{$prefix}_)#", '', $key);

captcha/non_gd.php

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function execute($code, $seed)
7878

7979
for ($j = 0; $j < $code_len; $j++)
8080
{
81+
/** @psalm-suppress InvalidArrayOffset */
8182
$image .= $this->randomise(substr($hold_chars[$code[$j]][$i - $offset_y - 1], 1), $char_widths[$j]);
8283
}
8384

config/config.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class config implements \ArrayAccess, \IteratorAggregate, \Countable
2727
/**
2828
* Creates a configuration container with a default set of values
2929
*
30-
* @param array<string,string> $config The configuration data.
30+
* @param array<string,int|string> $config The configuration data.
3131
*/
3232
public function __construct(array $config)
3333
{
@@ -74,22 +74,22 @@ public function offsetGet($key)
7474
* The configuration change will not persist. It will be lost
7575
* after the request.
7676
*
77-
* @param string $key The configuration option's name.
78-
* @param string $value The temporary value.
77+
* @param string $offset The configuration option's name.
78+
* @param int|string $value The temporary value.
7979
*/
8080
#[\ReturnTypeWillChange]
81-
public function offsetSet($key, $value)
81+
public function offsetSet($offset, $value)
8282
{
83-
$this->config[$key] = $value;
83+
$this->config[$offset] = $value;
8484
}
8585

8686
/**
8787
* Called when deleting a configuration value directly, triggers an error.
8888
*
89-
* @param string $key The configuration option's name.
89+
* @param string $offset The configuration option's name.
9090
*/
9191
#[\ReturnTypeWillChange]
92-
public function offsetUnset($key)
92+
public function offsetUnset($offset): never
9393
{
9494
trigger_error('Config values have to be deleted explicitly with the \phpbb\config\config::delete($key) method.', E_USER_ERROR);
9595
}
@@ -121,7 +121,7 @@ public function delete($key, $use_cache = true)
121121
* Sets a configuration option's value
122122
*
123123
* @param string $key The configuration option's name
124-
* @param string $value New configuration value
124+
* @param int|string $value New configuration value
125125
* @param bool $use_cache Whether this variable should be cached or if it
126126
* changes too frequently to be efficiently cached.
127127
*/
@@ -135,8 +135,8 @@ public function set($key, $value, $use_cache = true)
135135
* current configuration value or the configuration value does not exist yet.
136136
*
137137
* @param string $key The configuration option's name
138-
* @param string $old_value Current configuration value
139-
* @param string $new_value New configuration value
138+
* @param int|string $old_value Current configuration value
139+
* @param int|string $new_value New configuration value
140140
* @param bool $use_cache Whether this variable should be cached or if it
141141
* changes too frequently to be efficiently cached.
142142
* @return bool True if the value was changed, false otherwise.
@@ -157,7 +157,7 @@ public function set_atomic($key, $old_value, $new_value, $use_cache = true)
157157
* only after set_atomic has been called.
158158
*
159159
* @param string $key The configuration option's name
160-
* @param string $new_value New configuration value
160+
* @param int|string $new_value New configuration value
161161
* @throws \phpbb\exception\http_exception when config value is set and not equal to new_value.
162162
* @return bool True if the value was changed, false otherwise.
163163
*/

config/db.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ public function delete($key, $use_cache = true)
127127
/**
128128
* Sets a configuration option's value
129129
*
130-
* @param string $key The configuration option's name
131-
* @param string $value New configuration value
132-
* @param bool $use_cache Whether this variable should be cached or if it
133-
* changes too frequently to be efficiently cached.
130+
* @param string $key The configuration option's name
131+
* @param int|string $value New configuration value
132+
* @param bool $use_cache Whether this variable should be cached or if it
133+
* changes too frequently to be efficiently cached.
134134
*/
135135
public function set($key, $value, $use_cache = true)
136136
{
@@ -141,13 +141,13 @@ public function set($key, $value, $use_cache = true)
141141
* Sets a configuration option's value only if the old_value matches the
142142
* current configuration value or the configuration value does not exist yet.
143143
*
144-
* @param string $key The configuration option's name
145-
* @param mixed $old_value Current configuration value or false to ignore
146-
* the old value
147-
* @param string $new_value New configuration value
148-
* @param bool $use_cache Whether this variable should be cached or if it
149-
* changes too frequently to be efficiently cached
150-
* @return bool True if the value was changed, false otherwise
144+
* @param string $key The configuration option's name
145+
* @param false|int|string $old_value Current configuration value or false to ignore
146+
* the old value
147+
* @param int|string $new_value New configuration value
148+
* @param bool $use_cache Whether this variable should be cached or if it
149+
* changes too frequently to be efficiently cached
150+
* @return bool True if the value was changed, false otherwise
151151
*/
152152
public function set_atomic($key, $old_value, $new_value, $use_cache = true)
153153
{

cron/manager.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function __construct(ContainerInterface $phpbb_container, helper $routing
8686
* Loads tasks given by name, wraps them
8787
* and puts them into $this->tasks.
8888
*
89-
* @param array|\Traversable $tasks Array of instances of \phpbb\cron\task\task
89+
* @param array|\ArrayObject $tasks Array of instances of \phpbb\cron\task\task
9090
*/
9191
public function load_tasks($tasks)
9292
{
@@ -106,6 +106,7 @@ public function load_tasks_from_container()
106106
{
107107
$this->is_initialised_from_container = true;
108108

109+
/** @var array|\phpbb\di\service_collection $tasks */
109110
$tasks = $this->phpbb_container->get('cron.task_collection');
110111

111112
$this->load_tasks($tasks);

cron/task/core/tidy_plupload.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function run()
105105
));
106106
}
107107

108-
$this->config->set('plupload_last_gc', time(), true);
108+
$this->config->set('plupload_last_gc', time());
109109
}
110110

111111
/**

db/doctrine/type_converter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static function convert(string $type, string $dbms): array
7474
* @param string $type Legacy type name.
7575
* @param int $length Type length.
7676
*
77-
* @return array{string, array} Pair of type name and options.
77+
* @return array{string, array{string, ...}} Pair of type name and options.
7878
*/
7979
private static function mapWithLength(string $type, int $length): array
8080
{

db/driver/mssql_odbc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function sql_last_inserted_id()
279279
{
280280
$id = odbc_result($result_id, 1);
281281
odbc_free_result($result_id);
282-
return $id;
282+
return $id ? (int) $id : false;
283283
}
284284
odbc_free_result($result_id);
285285
}

db/migration/exception.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct()
4444
*
4545
* @return string
4646
*/
47-
public function __toString()
47+
public function __toString(): string
4848
{
4949
return $this->message . ': ' . var_export($this->parameters, true);
5050
}

db/migration/tool/module.php

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public function exists($class, $parent, $module, $lazy = false)
103103

104104
foreach ($parent_sqls as $parent_sql)
105105
{
106+
/** @psalm-suppress NoValue */
106107
$sql = 'SELECT module_id
107108
FROM ' . $this->modules_table . "
108109
WHERE module_class = '" . $this->db->sql_escape($class) . "'

di/container_builder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ protected function inject_dbal_driver()
587587
$this->config_php_file->get('dbname'),
588588
$this->config_php_file->get('dbport'),
589589
false,
590-
defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK
590+
defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false
591591
);
592592
}
593593
$this->container->set('dbal.conn.driver', $this->dbal_connection);

di/extension/container_configuration.php

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function getConfigTreeBuilder()
2828
{
2929
$treeBuilder = new TreeBuilder('core');
3030
$rootNode = $treeBuilder->getRootNode();
31+
/** @psalm-suppress UndefinedMethod */
3132
$rootNode
3233
->children()
3334
->booleanNode('require_dev_dependencies')->defaultValue(false)->end()

event/recursive_event_filter_iterator.php

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* This filter ignores directories and files starting with a dot.
1818
* It also skips some directories that do not contain events anyway,
1919
* such as e.g. files/, store/ and vendor/
20+
*
21+
* @psalm-suppress MissingTemplateParam
2022
*/
2123
class recursive_event_filter_iterator extends \RecursiveFilterIterator
2224
{

extension/provider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*
2424
* Items could be anything, for example template paths or cron task names.
2525
* Derived classes completely define what the items are.
26+
*
27+
* @psalm-suppress MissingTemplateParam
2628
*/
2729
abstract class provider implements \IteratorAggregate
2830
{
@@ -60,7 +62,7 @@ abstract protected function find();
6062
*
6163
* @return \ArrayIterator An iterator for the array of template paths
6264
*/
63-
public function getIterator()
65+
public function getIterator(): \ArrayIterator
6466
{
6567
if ($this->items === null)
6668
{

feed/topics_active.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private function get_forum_ids()
119119
FROM ' . FORUMS_TABLE . '
120120
WHERE forum_type = ' . FORUM_POST . '
121121
AND ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . '
122-
AND ' . $this->db->sql_bit_and('forum_flags', round(log(FORUM_FLAG_ACTIVE_TOPICS, 2)), '<> 0');
122+
AND ' . $this->db->sql_bit_and('forum_flags', (int) round(log(FORUM_FLAG_ACTIVE_TOPICS, 2)), '<> 0');
123123
$result = $this->db->sql_query($sql);
124124

125125
$forum_ids = array();

filesystem/filesystem.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ protected function phpbb_own_realpath($path)
632632
else if (function_exists('debug_backtrace'))
633633
{
634634
$call_stack = debug_backtrace(0);
635-
$this->working_directory = str_replace(DIRECTORY_SEPARATOR, '/', dirname($call_stack[count($call_stack) - 1]['file']));
635+
$this->working_directory = str_replace(DIRECTORY_SEPARATOR, '/', dirname($call_stack[max(0, count($call_stack) - 1)]['file']));
636636
}
637637
else
638638
{
@@ -686,6 +686,8 @@ protected function phpbb_own_realpath($path)
686686
return false;
687687
}
688688

689+
$resolved_path = (string) $resolved_path;
690+
689691
if (!@file_exists($resolved_path) || (!@is_dir($resolved_path . '/') && !is_file($resolved_path)))
690692
{
691693
return false;

filesystem/helper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected static function phpbb_own_realpath($path)
9797
else if (function_exists('debug_backtrace'))
9898
{
9999
$call_stack = debug_backtrace(0);
100-
$working_directory = str_replace(DIRECTORY_SEPARATOR, '/', dirname($call_stack[count($call_stack) - 1]['file']));
100+
$working_directory = str_replace(DIRECTORY_SEPARATOR, '/', dirname($call_stack[max(0, count($call_stack) - 1)]['file']));
101101
}
102102
else
103103
{
@@ -156,7 +156,7 @@ protected static function phpbb_own_realpath($path)
156156
}
157157

158158
// Return OS specific directory separators
159-
$resolved = str_replace('/', DIRECTORY_SEPARATOR, $resolved_path);
159+
$resolved = str_replace('/', DIRECTORY_SEPARATOR, (string) $resolved_path);
160160

161161
// Check for DIRECTORY_SEPARATOR at the end (and remove it!)
162162
if (substr($resolved, -1) === DIRECTORY_SEPARATOR)

finder/recursive_dot_prefix_filter_iterator.php

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* This filter ignores directories starting with a dot.
2020
* When searching for php classes and template files of extensions
2121
* we don't need to look inside these directories.
22+
*
23+
* @psalm-suppress MissingTemplateParam
2224
*/
2325
class recursive_dot_prefix_filter_iterator extends \RecursiveFilterIterator
2426
{

finder/recursive_path_iterator.php

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
namespace phpbb\finder;
1717

18+
/**
19+
* @psalm-suppress MissingTemplateParam
20+
*/
1821
class recursive_path_iterator extends \RecursiveIteratorIterator
1922
{
2023
/**

install/installer.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ public function run()
341341
/**
342342
* Recover install progress
343343
*
344-
* @return string Index of the next installer module to execute
344+
* @return int Index of the next installer module to execute
345345
*/
346-
protected function recover_progress()
346+
protected function recover_progress(): int
347347
{
348348
$progress_array = $this->install_config->get_progress_data();
349-
return $progress_array['last_task_module_index'];
349+
return (int) $progress_array['last_task_module_index'];
350350
}
351351
}

install/installer_configuration.php

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function getConfigTreeBuilder()
2828
{
2929
$treeBuilder = new TreeBuilder('installer');
3030
$rootNode = $treeBuilder->getRootNode();
31+
/** @psalm-suppress UndefinedMethod */
3132
$rootNode
3233
->children()
3334
->arrayNode('admin')

install/module/install_database/task/create_schema_file.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function run()
149149
$tables = [];
150150
foreach ($tables_data['parameters'] as $parameter => $table)
151151
{
152-
$tables[str_replace('tables.', '', $parameter)] = str_replace('%core.table_prefix%', $table_prefix, $table);
152+
$tables[str_replace('tables.', '', (string) $parameter)] = str_replace('%core.table_prefix%', $table_prefix, $table);
153153
}
154154

155155
$schema_generator = new \phpbb\db\migration\schema_generator(

install/module_base.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ public function run()
186186
/**
187187
* Returns the next task's name
188188
*
189-
* @return string Index of the array element of the next task
189+
* @return int Index of the array element of the next task
190190
*/
191-
protected function recover_progress()
191+
protected function recover_progress(): int
192192
{
193193
$progress_array = $this->install_config->get_progress_data();
194-
return $progress_array['last_task_index'];
194+
return (int) $progress_array['last_task_index'];
195195
}
196196

197197
/**

install/updater_configuration.php

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function getConfigTreeBuilder()
2828
{
2929
$treeBuilder = new TreeBuilder('updater');
3030
$rootNode = $treeBuilder->getRootNode();
31+
/** @psalm-suppress UndefinedMethod */
3132
$rootNode
3233
->addDefaultsIfNotSet()
3334
->children()

notification/manager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function mark_notifications_by_parent($notification_type_name, $item_pare
223223
* Mark notifications read or unread for a given method
224224
*
225225
* @param string $method_name
226-
* @param int|array $notification_id Notification id or array of notification ids.
226+
* @param array $notification_id Notification id or array of notification ids.
227227
* @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
228228
* @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
229229
*/

0 commit comments

Comments
 (0)