From c6c299eea4a7464f3686488c0f2c1ff92f4b9814 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 30 Dec 2023 10:07:23 +0100 Subject: [PATCH 1/5] [ticket/17281] Update to psalm 5.x PHPBB3-17281 --- phpBB/composer.json | 4 +- phpBB/composer.lock | 334 +++++++++++++++++++++++--------------------- psalm.xml | 2 + 3 files changed, 182 insertions(+), 158 deletions(-) diff --git a/phpBB/composer.json b/phpBB/composer.json index c565808659..4a6087997c 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -70,8 +70,8 @@ "symfony/css-selector": "^6.3", "symfony/dom-crawler": "^6.3", "symfony/http-client": "^6.3", - "vimeo/psalm": "^4.14", - "psalm/plugin-symfony": "^3.1" + "vimeo/psalm": "^5.18.0", + "psalm/plugin-symfony": "^v5.1.0" }, "suggest": { "ext-mbstring": "Better performance in search" diff --git a/phpBB/composer.lock b/phpBB/composer.lock index b879ff7273..ce9e34c5e2 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "214f00dfc71ef3bf2c81d6e3f7b579e5", + "content-hash": "92873eaf73cacda45801dcd603c021f2", "packages": [ { "name": "bantu/ini-get-wrapper", @@ -5728,6 +5728,67 @@ }, "time": "2022-03-02T22:36:06+00:00" }, + { + "name": "fidry/cpu-core-counter", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/theofidry/cpu-core-counter.git", + "reference": "85193c0b0cb5c47894b5eaec906e946f054e7077" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/85193c0b0cb5c47894b5eaec906e946f054e7077", + "reference": "85193c0b0cb5c47894b5eaec906e946f054e7077", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "fidry/makefile": "^0.2.0", + "fidry/php-cs-fixer-config": "^1.1.2", + "phpstan/extension-installer": "^1.2.0", + "phpstan/phpstan": "^1.9.2", + "phpstan/phpstan-deprecation-rules": "^1.0.0", + "phpstan/phpstan-phpunit": "^1.2.2", + "phpstan/phpstan-strict-rules": "^1.4.4", + "phpunit/phpunit": "^8.5.31 || ^9.5.26", + "webmozarts/strict-phpunit": "^7.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Fidry\\CpuCoreCounter\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Théo FIDRY", + "email": "theo.fidry@gmail.com" + } + ], + "description": "Tiny utility to get the number of CPU cores.", + "keywords": [ + "CPU", + "core" + ], + "support": { + "issues": "https://github.com/theofidry/cpu-core-counter/issues", + "source": "https://github.com/theofidry/cpu-core-counter/tree/1.0.0" + }, + "funding": [ + { + "url": "https://github.com/theofidry", + "type": "github" + } + ], + "time": "2023-09-17T21:38:23+00:00" + }, { "name": "laravel/homestead", "version": "v14.5.0", @@ -6070,59 +6131,6 @@ }, "time": "2023-12-10T21:03:43+00:00" }, - { - "name": "openlss/lib-array2xml", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/nullivex/lib-array2xml.git", - "reference": "a91f18a8dfc69ffabe5f9b068bc39bb202c81d90" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nullivex/lib-array2xml/zipball/a91f18a8dfc69ffabe5f9b068bc39bb202c81d90", - "reference": "a91f18a8dfc69ffabe5f9b068bc39bb202c81d90", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "type": "library", - "autoload": { - "psr-0": { - "LSS": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Bryan Tong", - "email": "bryan@nullivex.com", - "homepage": "https://www.nullivex.com" - }, - { - "name": "Tony Butler", - "email": "spudz76@gmail.com", - "homepage": "https://www.nullivex.com" - } - ], - "description": "Array2XML conversion library credit to lalit.org", - "homepage": "https://www.nullivex.com", - "keywords": [ - "array", - "array conversion", - "xml", - "xml conversion" - ], - "support": { - "issues": "https://github.com/nullivex/lib-array2xml/issues", - "source": "https://github.com/nullivex/lib-array2xml/tree/master" - }, - "time": "2019-03-29T20:06:56+00:00" - }, { "name": "phar-io/manifest", "version": "2.0.3", @@ -6985,37 +6993,37 @@ }, { "name": "psalm/plugin-symfony", - "version": "v3.1.10", + "version": "v5.1.0", "source": { "type": "git", "url": "https://github.com/psalm/psalm-plugin-symfony.git", - "reference": "5dca17839a6d48766ac760b8aa6d1f6d12759b28" + "reference": "f23ec3439743fb24f5c1101e52d032f23d5befa6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/psalm/psalm-plugin-symfony/zipball/5dca17839a6d48766ac760b8aa6d1f6d12759b28", - "reference": "5dca17839a6d48766ac760b8aa6d1f6d12759b28", + "url": "https://api.github.com/repos/psalm/psalm-plugin-symfony/zipball/f23ec3439743fb24f5c1101e52d032f23d5befa6", + "reference": "f23ec3439743fb24f5c1101e52d032f23d5befa6", "shasum": "" }, "require": { "ext-simplexml": "*", - "php": "^7.1 || ^8.0", - "symfony/framework-bundle": "^4.0 || ^5.0 || ^6.0", - "vimeo/psalm": "^4.12" + "php": "^7.4 || ^8.0", + "symfony/framework-bundle": "^5.0 || ^6.0 || ^7.0", + "vimeo/psalm": "^5.1" }, "require-dev": { - "doctrine/annotations": "^1.8", - "doctrine/orm": "^2.7", + "doctrine/annotations": "^1.8|^2", + "doctrine/orm": "^2.9", "phpunit/phpunit": "~7.5 || ~9.5", "symfony/cache-contracts": "^1.0 || ^2.0", "symfony/console": "*", - "symfony/form": "^4.0 || ^5.0 || ^6.0", - "symfony/messenger": "^4.2 || ^5.0 || ^6.0", + "symfony/form": "^5.0 || ^6.0 || ^7.0", + "symfony/messenger": "^5.0 || ^6.0 || ^7.0", "symfony/security-guard": "*", - "symfony/serializer": "^4.0 || ^5.0 || ^6.0", + "symfony/serializer": "^5.0 || ^6.0 || ^7.0", "symfony/validator": "*", "twig/twig": "^2.10 || ^3.0", - "weirdan/codeception-psalm-module": "^0.13.1" + "weirdan/codeception-psalm-module": "dev-master" }, "suggest": { "weirdan/doctrine-psalm-plugin": "If Doctrine is used, it is recommended install this plugin" @@ -7044,9 +7052,9 @@ "description": "Psalm Plugin for Symfony", "support": { "issues": "https://github.com/psalm/psalm-plugin-symfony/issues", - "source": "https://github.com/psalm/psalm-plugin-symfony/tree/v3.1.10" + "source": "https://github.com/psalm/psalm-plugin-symfony/tree/v5.1.0" }, - "time": "2022-10-22T13:09:05+00:00" + "time": "2023-11-12T10:04:27+00:00" }, { "name": "sebastian/cli-parser", @@ -8012,6 +8020,69 @@ ], "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "spatie/array-to-xml", + "version": "3.2.2", + "source": { + "type": "git", + "url": "https://github.com/spatie/array-to-xml.git", + "reference": "96be97e664c87613121d073ea39af4c74e57a7f8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/array-to-xml/zipball/96be97e664c87613121d073ea39af4c74e57a7f8", + "reference": "96be97e664c87613121d073ea39af4c74e57a7f8", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "php": "^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.2", + "pestphp/pest": "^1.21", + "spatie/pest-plugin-snapshots": "^1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\ArrayToXml\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://freek.dev", + "role": "Developer" + } + ], + "description": "Convert an array to xml", + "homepage": "https://github.com/spatie/array-to-xml", + "keywords": [ + "array", + "convert", + "xml" + ], + "support": { + "source": "https://github.com/spatie/array-to-xml/tree/3.2.2" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2023-11-14T14:08:51+00:00" + }, { "name": "squizlabs/php_codesniffer", "version": "3.8.0", @@ -8835,24 +8906,24 @@ }, { "name": "vimeo/psalm", - "version": "4.30.0", + "version": "5.18.0", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "d0bc6e25d89f649e4f36a534f330f8bb4643dd69" + "reference": "b113f3ed0259fd6e212d87c3df80eec95a6abf19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/d0bc6e25d89f649e4f36a534f330f8bb4643dd69", - "reference": "d0bc6e25d89f649e4f36a534f330f8bb4643dd69", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/b113f3ed0259fd6e212d87c3df80eec95a6abf19", + "reference": "b113f3ed0259fd6e212d87c3df80eec95a6abf19", "shasum": "" }, "require": { "amphp/amp": "^2.4.2", "amphp/byte-stream": "^1.5", - "composer/package-versions-deprecated": "^1.8.0", + "composer-runtime-api": "^2", "composer/semver": "^1.4 || ^2.0 || ^3.0", - "composer/xdebug-handler": "^1.1 || ^2.0 || ^3.0", + "composer/xdebug-handler": "^2.0 || ^3.0", "dnoegel/php-xdg-base-dir": "^0.1.1", "ext-ctype": "*", "ext-dom": "*", @@ -8861,35 +8932,38 @@ "ext-mbstring": "*", "ext-simplexml": "*", "ext-tokenizer": "*", - "felixfbecker/advanced-json-rpc": "^3.0.3", - "felixfbecker/language-server-protocol": "^1.5", + "felixfbecker/advanced-json-rpc": "^3.1", + "felixfbecker/language-server-protocol": "^1.5.2", + "fidry/cpu-core-counter": "^0.4.1 || ^0.5.1 || ^1.0.0", "netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0", - "nikic/php-parser": "^4.13", - "openlss/lib-array2xml": "^1.0", - "php": "^7.1|^8", - "sebastian/diff": "^3.0 || ^4.0", - "symfony/console": "^3.4.17 || ^4.1.6 || ^5.0 || ^6.0", - "symfony/polyfill-php80": "^1.25", - "webmozart/path-util": "^2.3" + "nikic/php-parser": "^4.16", + "php": "^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0", + "sebastian/diff": "^4.0 || ^5.0", + "spatie/array-to-xml": "^2.17.0 || ^3.0", + "symfony/console": "^4.1.6 || ^5.0 || ^6.0 || ^7.0", + "symfony/filesystem": "^5.4 || ^6.0 || ^7.0" + }, + "conflict": { + "nikic/php-parser": "4.17.0" }, "provide": { "psalm/psalm": "self.version" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.2", - "brianium/paratest": "^4.0||^6.0", + "amphp/phpunit-util": "^2.0", + "bamarni/composer-bin-plugin": "^1.4", + "brianium/paratest": "^6.9", "ext-curl": "*", + "mockery/mockery": "^1.5", + "nunomaduro/mock-final-classes": "^1.1", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpdocumentor/reflection-docblock": "^5", - "phpmyadmin/sql-parser": "5.1.0||dev-master", - "phpspec/prophecy": ">=1.9.0", - "phpstan/phpdoc-parser": "1.2.* || 1.6.4", - "phpunit/phpunit": "^9.0", - "psalm/plugin-phpunit": "^0.16", - "slevomat/coding-standard": "^7.0", - "squizlabs/php_codesniffer": "^3.5", - "symfony/process": "^4.3 || ^5.0 || ^6.0", - "weirdan/prophecy-shim": "^1.0 || ^2.0" + "phpstan/phpdoc-parser": "^1.6", + "phpunit/phpunit": "^9.6", + "psalm/plugin-mockery": "^1.1", + "psalm/plugin-phpunit": "^0.18", + "slevomat/coding-standard": "^8.4", + "squizlabs/php_codesniffer": "^3.6", + "symfony/process": "^4.4 || ^5.0 || ^6.0 || ^7.0" }, "suggest": { "ext-curl": "In order to send data to shepherd", @@ -8902,20 +8976,17 @@ "psalm-refactor", "psalter" ], - "type": "library", + "type": "project", "extra": { "branch-alias": { - "dev-master": "4.x-dev", + "dev-master": "5.x-dev", + "dev-4.x": "4.x-dev", "dev-3.x": "3.x-dev", "dev-2.x": "2.x-dev", "dev-1.x": "1.x-dev" } }, "autoload": { - "files": [ - "src/functions.php", - "src/spl_object_id.php" - ], "psr-4": { "Psalm\\": "src/Psalm/" } @@ -8933,13 +9004,15 @@ "keywords": [ "code", "inspection", - "php" + "php", + "static analysis" ], "support": { + "docs": "https://psalm.dev/docs", "issues": "https://github.com/vimeo/psalm/issues", - "source": "https://github.com/vimeo/psalm/tree/4.30.0" + "source": "https://github.com/vimeo/psalm" }, - "time": "2022-11-06T20:37:08+00:00" + "time": "2023-12-16T09:37:35+00:00" }, { "name": "webmozart/assert", @@ -8998,57 +9071,6 @@ "source": "https://github.com/webmozarts/assert/tree/1.11.0" }, "time": "2022-06-03T18:03:27+00:00" - }, - { - "name": "webmozart/path-util", - "version": "2.3.0", - "source": { - "type": "git", - "url": "https://github.com/webmozart/path-util.git", - "reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozart/path-util/zipball/d939f7edc24c9a1bb9c0dee5cb05d8e859490725", - "reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "webmozart/assert": "~1.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\PathUtil\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "A robust cross-platform utility for normalizing, comparing and modifying file paths.", - "support": { - "issues": "https://github.com/webmozart/path-util/issues", - "source": "https://github.com/webmozart/path-util/tree/2.3.0" - }, - "abandoned": "symfony/filesystem", - "time": "2015-12-17T08:42:14+00:00" } ], "aliases": [], diff --git a/psalm.xml b/psalm.xml index da3e19db9d..1308223525 100644 --- a/psalm.xml +++ b/psalm.xml @@ -2,6 +2,8 @@ Date: Sat, 30 Dec 2023 17:41:12 +0100 Subject: [PATCH 2/5] [ticket/17281] Update psalm config and fix issues PHPBB3-17281 --- phpBB/includes/functions_content.php | 2 ++ phpBB/phpbb/attachment/upload.php | 1 + phpBB/phpbb/avatar/manager.php | 4 ++-- phpBB/phpbb/captcha/non_gd.php | 1 + phpBB/phpbb/config/config.php | 22 +++++++++---------- phpBB/phpbb/config/db.php | 22 +++++++++---------- phpBB/phpbb/cron/manager.php | 3 ++- phpBB/phpbb/cron/task/core/tidy_plupload.php | 2 +- phpBB/phpbb/db/doctrine/type_converter.php | 2 +- phpBB/phpbb/db/driver/mssql_odbc.php | 2 +- phpBB/phpbb/db/migration/exception.php | 2 +- phpBB/phpbb/db/migration/tool/module.php | 1 + phpBB/phpbb/di/container_builder.php | 2 +- .../di/extension/container_configuration.php | 1 + .../event/recursive_event_filter_iterator.php | 2 ++ phpBB/phpbb/extension/provider.php | 4 +++- phpBB/phpbb/feed/topics_active.php | 2 +- phpBB/phpbb/filesystem/filesystem.php | 4 +++- phpBB/phpbb/filesystem/helper.php | 4 ++-- .../recursive_dot_prefix_filter_iterator.php | 2 ++ .../phpbb/finder/recursive_path_iterator.php | 3 +++ phpBB/phpbb/install/installer.php | 6 ++--- .../phpbb/install/installer_configuration.php | 1 + .../task/create_schema_file.php | 2 +- phpBB/phpbb/install/module_base.php | 6 ++--- phpBB/phpbb/install/updater_configuration.php | 1 + phpBB/phpbb/notification/manager.php | 2 +- .../notification/method/method_interface.php | 8 +++---- phpBB/phpbb/pagination.php | 4 ++-- phpBB/phpbb/passwords/driver/helper.php | 4 ++-- phpBB/phpbb/plupload/plupload.php | 4 ++-- phpBB/phpbb/report/controller/report.php | 2 +- .../request/deactivated_super_global.php | 15 +++++++------ phpBB/phpbb/routing/file_locator.php | 6 ++++- .../phpbb/search/backend/fulltext_native.php | 2 +- phpBB/phpbb/session.php | 10 ++++----- phpBB/phpbb/template/context.php | 4 ++-- phpBB/phpbb/template/template.php | 4 ++-- phpBB/phpbb/template/twig/extension/icon.php | 2 +- phpBB/phpbb/tree/nestedset.php | 10 ++++----- phpBB/phpbb/user.php | 4 ++-- psalm.xml | 2 ++ 42 files changed, 107 insertions(+), 80 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 3dc8e2c8e0..2f81c0db8d 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -554,6 +554,8 @@ function strip_bbcode(&$text, $uid = '') /** * For display of custom parsed text on user-facing pages * Expects $text to be the value directly from the database (stored value) +* +* @return string Generated text */ function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text = true) { diff --git a/phpBB/phpbb/attachment/upload.php b/phpBB/phpbb/attachment/upload.php index dccd74dbc3..d5b961de5f 100644 --- a/phpBB/phpbb/attachment/upload.php +++ b/phpBB/phpbb/attachment/upload.php @@ -219,6 +219,7 @@ class upload $this->storage->delete($thumbnail_file); } + /** @psalm-suppress NoValue */ $this->file_data['error'] = array_merge($this->file_data['error'], $this->file->error); $this->file_data['post_attach'] = false; diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 17fbae09d9..18b198caa7 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -190,7 +190,7 @@ class manager * @param array $row User data or group data * @param string $prefix Prefix of data keys (e.g. user), should not include the trailing underscore * - * @return array User or group data with keys that have been + * @return array{string, string} User or group data with keys that have been * stripped from the preceding "user_" or "group_" * Also the group id is prefixed with g, when the prefix group is removed. */ @@ -202,7 +202,7 @@ class manager return self::$default_row; } - $output = array(); + $output = []; foreach ($row as $key => $value) { $key = preg_replace("#^(?:{$prefix}_)#", '', $key); diff --git a/phpBB/phpbb/captcha/non_gd.php b/phpBB/phpbb/captcha/non_gd.php index 8105187ed9..881701c7d3 100644 --- a/phpBB/phpbb/captcha/non_gd.php +++ b/phpBB/phpbb/captcha/non_gd.php @@ -78,6 +78,7 @@ class non_gd for ($j = 0; $j < $code_len; $j++) { + /** @psalm-suppress InvalidArrayOffset */ $image .= $this->randomise(substr($hold_chars[$code[$j]][$i - $offset_y - 1], 1), $char_widths[$j]); } diff --git a/phpBB/phpbb/config/config.php b/phpBB/phpbb/config/config.php index ae2ce658f2..3e62c29b1b 100644 --- a/phpBB/phpbb/config/config.php +++ b/phpBB/phpbb/config/config.php @@ -27,7 +27,7 @@ class config implements \ArrayAccess, \IteratorAggregate, \Countable /** * Creates a configuration container with a default set of values * - * @param array $config The configuration data. + * @param array $config The configuration data. */ public function __construct(array $config) { @@ -74,22 +74,22 @@ class config implements \ArrayAccess, \IteratorAggregate, \Countable * The configuration change will not persist. It will be lost * after the request. * - * @param string $key The configuration option's name. - * @param string $value The temporary value. + * @param string $offset The configuration option's name. + * @param int|string $value The temporary value. */ #[\ReturnTypeWillChange] - public function offsetSet($key, $value) + public function offsetSet($offset, $value) { - $this->config[$key] = $value; + $this->config[$offset] = $value; } /** * Called when deleting a configuration value directly, triggers an error. * - * @param string $key The configuration option's name. + * @param string $offset The configuration option's name. */ #[\ReturnTypeWillChange] - public function offsetUnset($key) + public function offsetUnset($offset): never { trigger_error('Config values have to be deleted explicitly with the \phpbb\config\config::delete($key) method.', E_USER_ERROR); } @@ -121,7 +121,7 @@ class config implements \ArrayAccess, \IteratorAggregate, \Countable * Sets a configuration option's value * * @param string $key The configuration option's name - * @param string $value New configuration value + * @param int|string $value New configuration value * @param bool $use_cache Whether this variable should be cached or if it * changes too frequently to be efficiently cached. */ @@ -135,8 +135,8 @@ class config implements \ArrayAccess, \IteratorAggregate, \Countable * current configuration value or the configuration value does not exist yet. * * @param string $key The configuration option's name - * @param string $old_value Current configuration value - * @param string $new_value New configuration value + * @param int|string $old_value Current configuration value + * @param int|string $new_value New configuration value * @param bool $use_cache Whether this variable should be cached or if it * changes too frequently to be efficiently cached. * @return bool True if the value was changed, false otherwise. @@ -157,7 +157,7 @@ class config implements \ArrayAccess, \IteratorAggregate, \Countable * only after set_atomic has been called. * * @param string $key The configuration option's name - * @param string $new_value New configuration value + * @param int|string $new_value New configuration value * @throws \phpbb\exception\http_exception when config value is set and not equal to new_value. * @return bool True if the value was changed, false otherwise. */ diff --git a/phpBB/phpbb/config/db.php b/phpBB/phpbb/config/db.php index a346164db2..bbb97d0bbd 100644 --- a/phpBB/phpbb/config/db.php +++ b/phpBB/phpbb/config/db.php @@ -127,10 +127,10 @@ class db extends config /** * Sets a configuration option's value * - * @param string $key The configuration option's name - * @param string $value New configuration value - * @param bool $use_cache Whether this variable should be cached or if it - * changes too frequently to be efficiently cached. + * @param string $key The configuration option's name + * @param int|string $value New configuration value + * @param bool $use_cache Whether this variable should be cached or if it + * changes too frequently to be efficiently cached. */ public function set($key, $value, $use_cache = true) { @@ -141,13 +141,13 @@ class db extends config * Sets a configuration option's value only if the old_value matches the * current configuration value or the configuration value does not exist yet. * - * @param string $key The configuration option's name - * @param mixed $old_value Current configuration value or false to ignore - * the old value - * @param string $new_value New configuration value - * @param bool $use_cache Whether this variable should be cached or if it - * changes too frequently to be efficiently cached - * @return bool True if the value was changed, false otherwise + * @param string $key The configuration option's name + * @param false|int|string $old_value Current configuration value or false to ignore + * the old value + * @param int|string $new_value New configuration value + * @param bool $use_cache Whether this variable should be cached or if it + * changes too frequently to be efficiently cached + * @return bool True if the value was changed, false otherwise */ public function set_atomic($key, $old_value, $new_value, $use_cache = true) { diff --git a/phpBB/phpbb/cron/manager.php b/phpBB/phpbb/cron/manager.php index 8a64acc4a5..70fec0d127 100644 --- a/phpBB/phpbb/cron/manager.php +++ b/phpBB/phpbb/cron/manager.php @@ -86,7 +86,7 @@ class manager * Loads tasks given by name, wraps them * and puts them into $this->tasks. * - * @param array|\Traversable $tasks Array of instances of \phpbb\cron\task\task + * @param array|\ArrayObject $tasks Array of instances of \phpbb\cron\task\task */ public function load_tasks($tasks) { @@ -106,6 +106,7 @@ class manager { $this->is_initialised_from_container = true; + /** @var array|\phpbb\di\service_collection $tasks */ $tasks = $this->phpbb_container->get('cron.task_collection'); $this->load_tasks($tasks); diff --git a/phpBB/phpbb/cron/task/core/tidy_plupload.php b/phpBB/phpbb/cron/task/core/tidy_plupload.php index 37d0e9b21a..fd008c92dc 100644 --- a/phpBB/phpbb/cron/task/core/tidy_plupload.php +++ b/phpBB/phpbb/cron/task/core/tidy_plupload.php @@ -105,7 +105,7 @@ class tidy_plupload extends \phpbb\cron\task\base )); } - $this->config->set('plupload_last_gc', time(), true); + $this->config->set('plupload_last_gc', time()); } /** diff --git a/phpBB/phpbb/db/doctrine/type_converter.php b/phpBB/phpbb/db/doctrine/type_converter.php index 1de09e821c..721318f963 100644 --- a/phpBB/phpbb/db/doctrine/type_converter.php +++ b/phpBB/phpbb/db/doctrine/type_converter.php @@ -74,7 +74,7 @@ class type_converter * @param string $type Legacy type name. * @param int $length Type length. * - * @return array{string, array} Pair of type name and options. + * @return array{string, array{string, ...}} Pair of type name and options. */ private static function mapWithLength(string $type, int $length): array { diff --git a/phpBB/phpbb/db/driver/mssql_odbc.php b/phpBB/phpbb/db/driver/mssql_odbc.php index 9b91aa8e0e..95bf2ebed3 100644 --- a/phpBB/phpbb/db/driver/mssql_odbc.php +++ b/phpBB/phpbb/db/driver/mssql_odbc.php @@ -279,7 +279,7 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base { $id = odbc_result($result_id, 1); odbc_free_result($result_id); - return $id; + return $id ? (int) $id : false; } odbc_free_result($result_id); } diff --git a/phpBB/phpbb/db/migration/exception.php b/phpBB/phpbb/db/migration/exception.php index 7990e85f2d..930a878dc1 100644 --- a/phpBB/phpbb/db/migration/exception.php +++ b/phpBB/phpbb/db/migration/exception.php @@ -44,7 +44,7 @@ class exception extends \Exception * * @return string */ - public function __toString() + public function __toString(): string { return $this->message . ': ' . var_export($this->parameters, true); } diff --git a/phpBB/phpbb/db/migration/tool/module.php b/phpBB/phpbb/db/migration/tool/module.php index 407945e6db..2aeec109a4 100644 --- a/phpBB/phpbb/db/migration/tool/module.php +++ b/phpBB/phpbb/db/migration/tool/module.php @@ -103,6 +103,7 @@ class module implements \phpbb\db\migration\tool\tool_interface foreach ($parent_sqls as $parent_sql) { + /** @psalm-suppress NoValue */ $sql = 'SELECT module_id FROM ' . $this->modules_table . " WHERE module_class = '" . $this->db->sql_escape($class) . "' diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 4dc91b7409..46e7edffd2 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -587,7 +587,7 @@ class container_builder $this->config_php_file->get('dbname'), $this->config_php_file->get('dbport'), false, - defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK + defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false ); } $this->container->set('dbal.conn.driver', $this->dbal_connection); diff --git a/phpBB/phpbb/di/extension/container_configuration.php b/phpBB/phpbb/di/extension/container_configuration.php index c0f3080953..6d68a5170a 100644 --- a/phpBB/phpbb/di/extension/container_configuration.php +++ b/phpBB/phpbb/di/extension/container_configuration.php @@ -28,6 +28,7 @@ class container_configuration implements ConfigurationInterface { $treeBuilder = new TreeBuilder('core'); $rootNode = $treeBuilder->getRootNode(); + /** @psalm-suppress UndefinedMethod */ $rootNode ->children() ->booleanNode('require_dev_dependencies')->defaultValue(false)->end() diff --git a/phpBB/phpbb/event/recursive_event_filter_iterator.php b/phpBB/phpbb/event/recursive_event_filter_iterator.php index f671c474d9..ed5277d5b3 100644 --- a/phpBB/phpbb/event/recursive_event_filter_iterator.php +++ b/phpBB/phpbb/event/recursive_event_filter_iterator.php @@ -17,6 +17,8 @@ namespace phpbb\event; * This filter ignores directories and files starting with a dot. * It also skips some directories that do not contain events anyway, * such as e.g. files/, store/ and vendor/ +* +* @psalm-suppress MissingTemplateParam */ class recursive_event_filter_iterator extends \RecursiveFilterIterator { diff --git a/phpBB/phpbb/extension/provider.php b/phpBB/phpbb/extension/provider.php index 1c42cf7b5e..8432f956cb 100644 --- a/phpBB/phpbb/extension/provider.php +++ b/phpBB/phpbb/extension/provider.php @@ -23,6 +23,8 @@ namespace phpbb\extension; * * Items could be anything, for example template paths or cron task names. * Derived classes completely define what the items are. +* +* @psalm-suppress MissingTemplateParam */ abstract class provider implements \IteratorAggregate { @@ -60,7 +62,7 @@ abstract class provider implements \IteratorAggregate * * @return \ArrayIterator An iterator for the array of template paths */ - public function getIterator() + public function getIterator(): \ArrayIterator { if ($this->items === null) { diff --git a/phpBB/phpbb/feed/topics_active.php b/phpBB/phpbb/feed/topics_active.php index ee7fe177f5..bed47bec9b 100644 --- a/phpBB/phpbb/feed/topics_active.php +++ b/phpBB/phpbb/feed/topics_active.php @@ -119,7 +119,7 @@ class topics_active extends topic_base FROM ' . FORUMS_TABLE . ' WHERE forum_type = ' . FORUM_POST . ' AND ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . ' - AND ' . $this->db->sql_bit_and('forum_flags', round(log(FORUM_FLAG_ACTIVE_TOPICS, 2)), '<> 0'); + AND ' . $this->db->sql_bit_and('forum_flags', (int) round(log(FORUM_FLAG_ACTIVE_TOPICS, 2)), '<> 0'); $result = $this->db->sql_query($sql); $forum_ids = array(); diff --git a/phpBB/phpbb/filesystem/filesystem.php b/phpBB/phpbb/filesystem/filesystem.php index 39e95acc98..6324c5c209 100644 --- a/phpBB/phpbb/filesystem/filesystem.php +++ b/phpBB/phpbb/filesystem/filesystem.php @@ -632,7 +632,7 @@ class filesystem implements filesystem_interface else if (function_exists('debug_backtrace')) { $call_stack = debug_backtrace(0); - $this->working_directory = str_replace(DIRECTORY_SEPARATOR, '/', dirname($call_stack[count($call_stack) - 1]['file'])); + $this->working_directory = str_replace(DIRECTORY_SEPARATOR, '/', dirname($call_stack[max(0, count($call_stack) - 1)]['file'])); } else { @@ -686,6 +686,8 @@ class filesystem implements filesystem_interface return false; } + $resolved_path = (string) $resolved_path; + if (!@file_exists($resolved_path) || (!@is_dir($resolved_path . '/') && !is_file($resolved_path))) { return false; diff --git a/phpBB/phpbb/filesystem/helper.php b/phpBB/phpbb/filesystem/helper.php index 9d1c19057e..d7efc3d19b 100644 --- a/phpBB/phpbb/filesystem/helper.php +++ b/phpBB/phpbb/filesystem/helper.php @@ -97,7 +97,7 @@ class helper else if (function_exists('debug_backtrace')) { $call_stack = debug_backtrace(0); - $working_directory = str_replace(DIRECTORY_SEPARATOR, '/', dirname($call_stack[count($call_stack) - 1]['file'])); + $working_directory = str_replace(DIRECTORY_SEPARATOR, '/', dirname($call_stack[max(0, count($call_stack) - 1)]['file'])); } else { @@ -156,7 +156,7 @@ class helper } // Return OS specific directory separators - $resolved = str_replace('/', DIRECTORY_SEPARATOR, $resolved_path); + $resolved = str_replace('/', DIRECTORY_SEPARATOR, (string) $resolved_path); // Check for DIRECTORY_SEPARATOR at the end (and remove it!) if (substr($resolved, -1) === DIRECTORY_SEPARATOR) diff --git a/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php b/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php index e4f9ea1d8a..2a07638086 100644 --- a/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php +++ b/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php @@ -19,6 +19,8 @@ namespace phpbb\finder; * This filter ignores directories starting with a dot. * When searching for php classes and template files of extensions * we don't need to look inside these directories. +* +* @psalm-suppress MissingTemplateParam */ class recursive_dot_prefix_filter_iterator extends \RecursiveFilterIterator { diff --git a/phpBB/phpbb/finder/recursive_path_iterator.php b/phpBB/phpbb/finder/recursive_path_iterator.php index f93a240af2..8a3418dd87 100644 --- a/phpBB/phpbb/finder/recursive_path_iterator.php +++ b/phpBB/phpbb/finder/recursive_path_iterator.php @@ -15,6 +15,9 @@ declare(strict_types=1); namespace phpbb\finder; +/** + * @psalm-suppress MissingTemplateParam + */ class recursive_path_iterator extends \RecursiveIteratorIterator { /** diff --git a/phpBB/phpbb/install/installer.php b/phpBB/phpbb/install/installer.php index 26c1c8a0f6..23ab5df919 100644 --- a/phpBB/phpbb/install/installer.php +++ b/phpBB/phpbb/install/installer.php @@ -341,11 +341,11 @@ class installer /** * Recover install progress * - * @return string Index of the next installer module to execute + * @return int Index of the next installer module to execute */ - protected function recover_progress() + protected function recover_progress(): int { $progress_array = $this->install_config->get_progress_data(); - return $progress_array['last_task_module_index']; + return (int) $progress_array['last_task_module_index']; } } diff --git a/phpBB/phpbb/install/installer_configuration.php b/phpBB/phpbb/install/installer_configuration.php index efa2a922c3..974080dc55 100644 --- a/phpBB/phpbb/install/installer_configuration.php +++ b/phpBB/phpbb/install/installer_configuration.php @@ -28,6 +28,7 @@ class installer_configuration implements ConfigurationInterface { $treeBuilder = new TreeBuilder('installer'); $rootNode = $treeBuilder->getRootNode(); + /** @psalm-suppress UndefinedMethod */ $rootNode ->children() ->arrayNode('admin') diff --git a/phpBB/phpbb/install/module/install_database/task/create_schema_file.php b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php index 59a40e605f..e75bca65dc 100644 --- a/phpBB/phpbb/install/module/install_database/task/create_schema_file.php +++ b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php @@ -149,7 +149,7 @@ class create_schema_file extends \phpbb\install\task_base $tables = []; foreach ($tables_data['parameters'] as $parameter => $table) { - $tables[str_replace('tables.', '', $parameter)] = str_replace('%core.table_prefix%', $table_prefix, $table); + $tables[str_replace('tables.', '', (string) $parameter)] = str_replace('%core.table_prefix%', $table_prefix, $table); } $schema_generator = new \phpbb\db\migration\schema_generator( diff --git a/phpBB/phpbb/install/module_base.php b/phpBB/phpbb/install/module_base.php index 85ac4506c7..cddde12bb5 100644 --- a/phpBB/phpbb/install/module_base.php +++ b/phpBB/phpbb/install/module_base.php @@ -186,12 +186,12 @@ abstract class module_base implements module_interface /** * Returns the next task's name * - * @return string Index of the array element of the next task + * @return int Index of the array element of the next task */ - protected function recover_progress() + protected function recover_progress(): int { $progress_array = $this->install_config->get_progress_data(); - return $progress_array['last_task_index']; + return (int) $progress_array['last_task_index']; } /** diff --git a/phpBB/phpbb/install/updater_configuration.php b/phpBB/phpbb/install/updater_configuration.php index 2afdb44dfc..519de3bd2b 100644 --- a/phpBB/phpbb/install/updater_configuration.php +++ b/phpBB/phpbb/install/updater_configuration.php @@ -28,6 +28,7 @@ class updater_configuration implements ConfigurationInterface { $treeBuilder = new TreeBuilder('updater'); $rootNode = $treeBuilder->getRootNode(); + /** @psalm-suppress UndefinedMethod */ $rootNode ->addDefaultsIfNotSet() ->children() diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index 9c4fe8203a..2e78c9b570 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -223,7 +223,7 @@ class manager * Mark notifications read or unread for a given method * * @param string $method_name - * @param int|array $notification_id Notification id or array of notification ids. + * @param array $notification_id Notification id or array of notification ids. * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) * @param bool $mark_read Define if the notification as to be set to True or False. (Default: True) */ diff --git a/phpBB/phpbb/notification/method/method_interface.php b/phpBB/phpbb/notification/method/method_interface.php index 2bade743ed..28100d755f 100644 --- a/phpBB/phpbb/notification/method/method_interface.php +++ b/phpBB/phpbb/notification/method/method_interface.php @@ -91,7 +91,7 @@ interface method_interface /** * Mark notifications read or unread * - * @param bool|string $notification_type_id Type identifier of item types. False to mark read for all item types + * @param bool|string|array $notification_type_id Type identifier of item types. False to mark read for all item types * @param bool|int|array $item_id Item id or array of item ids. False to mark read for all item ids * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) @@ -113,7 +113,7 @@ interface method_interface /** * Mark notifications read or unread * - * @param int $notification_id Notification id of notification ids. + * @param array|int $notification_id Notification id or array of notification ids. * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) * @param bool $mark_read Define if the notification as to be set to True or False. (Default: True) */ @@ -122,7 +122,7 @@ interface method_interface /** * Delete a notification * - * @param string $notification_type_id Type identifier of item types + * @param int $notification_type_id Type identifier of item types * @param int|array $item_id Identifier within the type (or array of ids) * @param mixed $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified (Default: false; not checked) * @param mixed $user_id User id (Default: false; not checked) @@ -143,7 +143,7 @@ interface method_interface * This should be called when an extension which has notification types * is purged so that all those notifications are removed * - * @param string $notification_type_id Type identifier of the subscription + * @param int $notification_type_id Type identifier of the subscription */ public function purge_notifications($notification_type_id); } diff --git a/phpBB/phpbb/pagination.php b/phpBB/phpbb/pagination.php index e07c2988c1..a754dcbd13 100644 --- a/phpBB/phpbb/pagination.php +++ b/phpBB/phpbb/pagination.php @@ -49,7 +49,7 @@ class pagination * @param string|array $base_url is url prepended to all links generated within the function * If you use page numbers inside your controller route, base_url should contains a placeholder (%d) * for the page. Also be sure to specify the pagination path information into the start_name argument - * @param string $on_page is the page for which we want to generate the link + * @param int $on_page is the page for which we want to generate the link * @param string $start_name is the name of the parameter containing the first item of the given page (example: start=20) * If you use page numbers inside your controller route, start name should be the string * that should be removed for the first page (example: /page/%d) @@ -72,7 +72,7 @@ class pagination * @var string|array base_url is url prepended to all links generated within the function * If you use page numbers inside your controller route, base_url should contains a placeholder (%d) * for the page. Also be sure to specify the pagination path information into the start_name argument - * @var string on_page is the page for which we want to generate the link + * @var int on_page is the page for which we want to generate the link * @var string start_name is the name of the parameter containing the first item of the given page (example: start=20) * If you use page numbers inside your controller route, start name should be the string * that should be removed for the first page (example: /page/%d) diff --git a/phpBB/phpbb/passwords/driver/helper.php b/phpBB/phpbb/passwords/driver/helper.php index f80c3e3df6..c00054cb6b 100644 --- a/phpBB/phpbb/passwords/driver/helper.php +++ b/phpBB/phpbb/passwords/driver/helper.php @@ -102,8 +102,8 @@ class helper if ($dss_seeded !== true && ($this->config['rand_seed_last_update'] < time() - rand(1,10))) { - $this->config->set('rand_seed_last_update', time(), true); - $this->config->set('rand_seed', $this->config['rand_seed'], true); + $this->config->set('rand_seed_last_update', time()); + $this->config->set('rand_seed', $this->config['rand_seed']); $dss_seeded = true; } diff --git a/phpBB/phpbb/plupload/plupload.php b/phpBB/phpbb/plupload/plupload.php index 6ccb141313..db5a1d6dd9 100644 --- a/phpBB/phpbb/plupload/plupload.php +++ b/phpBB/phpbb/plupload/plupload.php @@ -221,11 +221,11 @@ class plupload * appropriate for use in configuring plupload with * * @param \phpbb\cache\service $cache Cache service object - * @param string $forum_id The forum identifier + * @param int $forum_id The forum identifier * * @return string */ - public function generate_filter_string(\phpbb\cache\service $cache, $forum_id) + public function generate_filter_string(\phpbb\cache\service $cache, int $forum_id) { $groups = []; $filters = []; diff --git a/phpBB/phpbb/report/controller/report.php b/phpBB/phpbb/report/controller/report.php index 1af565e6a0..b8e2b04583 100644 --- a/phpBB/phpbb/report/controller/report.php +++ b/phpBB/phpbb/report/controller/report.php @@ -250,7 +250,7 @@ class report /** * Assigns template variables * - * @param int $mode + * @param string $mode * @param int $id * @param int $reason_id * @param string $report_text diff --git a/phpBB/phpbb/request/deactivated_super_global.php b/phpBB/phpbb/request/deactivated_super_global.php index 4160c3696b..af4349d477 100644 --- a/phpBB/phpbb/request/deactivated_super_global.php +++ b/phpBB/phpbb/request/deactivated_super_global.php @@ -16,6 +16,7 @@ namespace phpbb\request; /** * Replacement for a superglobal (like $_GET or $_POST) which calls * trigger_error on all operations but isset, overloads the [] operator with SPL. +* @psalm-suppress MissingTemplateParam */ class deactivated_super_global implements \ArrayAccess, \Countable, \IteratorAggregate { @@ -25,23 +26,23 @@ class deactivated_super_global implements \ArrayAccess, \Countable, \IteratorAgg private $name; /** - * @var string (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) Super global constant. + * @var int (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) Super global constant. */ private $super_global; /** - * @var \phpbb\request\request_interface The request class instance holding the actual request data. + * @var request_interface The request class instance holding the actual request data. */ private $request; /** * Constructor generates an error message fitting the super global to be used within the other functions. * - * @param \phpbb\request\request_interface $request A request class instance holding the real super global data. - * @param string $name Name of the super global this is a replacement for - e.g. '_GET'. - * @param string $super_global The variable's super global constant (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE). + * @param request_interface $request A request class instance holding the real super global data. + * @param string $name Name of the super global this is a replacement for - e.g. '_GET'. + * @param int $super_global The variable's super global constant (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE). */ - public function __construct(\phpbb\request\request_interface $request, $name, $super_global) + public function __construct(request_interface $request, string $name, int $super_global) { $this->request = $request; $this->name = $name; @@ -82,7 +83,7 @@ class deactivated_super_global implements \ArrayAccess, \Countable, \IteratorAgg /**#@+ * Part of the \ArrayAccess implementation, will always result in a FATAL error. */ - public function offsetGet($offset): mixed + public function offsetGet($offset): void { $this->error(); } diff --git a/phpBB/phpbb/routing/file_locator.php b/phpBB/phpbb/routing/file_locator.php index bd2c1850bb..ae8e2a3a28 100644 --- a/phpBB/phpbb/routing/file_locator.php +++ b/phpBB/phpbb/routing/file_locator.php @@ -25,7 +25,11 @@ class file_locator extends FileLocator foreach ($paths as $path) { - $absolute_paths[] = filesystem_helper::realpath($path); + $path = filesystem_helper::realpath($path); + if ($path !== false) + { + $absolute_paths[] = $path; + } } parent::__construct($absolute_paths); diff --git a/phpBB/phpbb/search/backend/fulltext_native.php b/phpBB/phpbb/search/backend/fulltext_native.php index 56161d3eb2..67554b51e3 100644 --- a/phpBB/phpbb/search/backend/fulltext_native.php +++ b/phpBB/phpbb/search/backend/fulltext_native.php @@ -1718,7 +1718,7 @@ class fulltext_native extends base implements search_backend_interface /** * Clean up the string, remove HTML tags, remove BBCodes */ - $word = strtok($this->cleanup(preg_replace($match, ' ', strip_tags($text)), -1), ' '); + $word = strtok($this->cleanup(preg_replace($match, ' ', strip_tags($text)), '-1'), ' '); while (strlen($word)) { diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php index 4c2471ab92..c576ae3ef2 100644 --- a/phpBB/phpbb/session.php +++ b/phpBB/phpbb/session.php @@ -61,12 +61,12 @@ class session $script_name = str_replace(array('\\', '//'), '/', $script_name); // Now, remove the sid and let us get a clean query string... - $use_args = array(); + $use_args = []; // Since some browser do not encode correctly we need to do this with some "special" characters... // " -> %22, ' => %27, < -> %3C, > -> %3E - $find = array('"', "'", '<', '>', '"', '<', '>'); - $replace = array('%22', '%27', '%3C', '%3E', '%22', '%3C', '%3E'); + $find = ['"', "'", '<', '>', '"', '<', '>']; + $replace = ['%22', '%27', '%3C', '%3E', '%22', '%3C', '%3E']; foreach ($args as $argument) { @@ -75,7 +75,7 @@ class session continue; } - $use_args[] = str_replace($find, $replace, $argument); + $use_args[] = (string) str_replace($find, $replace, $argument); } unset($args); @@ -530,7 +530,7 @@ class session { if ($row['bot_agent'] && preg_match('#' . str_replace('\*', '.*?', preg_quote($row['bot_agent'], '#')) . '#i', $this->browser)) { - $bot = $row['user_id']; + $bot = (int) $row['user_id']; } // If ip is supplied, we will make sure the ip is matching too... diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index 7f83152590..b510c88ad5 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -60,10 +60,10 @@ class context * Value can be a string, an integer or a boolean. * * @param string $varname Variable name - * @param string $varval Value to assign to variable + * @param bool|int|string $varval Value to assign to variable * @return true */ - public function assign_var($varname, $varval) + public function assign_var(string $varname, bool|int|string $varval) { $this->rootref[$varname] = $varval; diff --git a/phpBB/phpbb/template/template.php b/phpBB/phpbb/template/template.php index dcc530f37a..c251513698 100644 --- a/phpBB/phpbb/template/template.php +++ b/phpBB/phpbb/template/template.php @@ -103,10 +103,10 @@ interface template * Value can be a string, an integer or a boolean. * * @param string $varname Variable name - * @param string $varval Value to assign to variable + * @param bool|int|string $varval Value to assign to variable * @return \phpbb\template\template $this */ - public function assign_var($varname, $varval); + public function assign_var(string $varname, bool|int|string $varval); /** * Append text to the string value stored in a key. diff --git a/phpBB/phpbb/template/twig/extension/icon.php b/phpBB/phpbb/template/twig/extension/icon.php index cea96b1992..72aa710fbc 100644 --- a/phpBB/phpbb/template/twig/extension/icon.php +++ b/phpBB/phpbb/template/twig/extension/icon.php @@ -58,7 +58,7 @@ class icon extends AbstractExtension * * @param environment $environment Twig environment object * @param string $type Icon type (font|iconify|png|svg) - * @param string $icon Icon name (eg. "bold") + * @param array|string $icon Icon name (eg. "bold") * @param string $title Icon title * @param bool $hidden Hide the icon title from view * @param string $classes Additional classes (eg. "fa-fw") diff --git a/phpBB/phpbb/tree/nestedset.php b/phpBB/phpbb/tree/nestedset.php index 3a32710ebc..8c3d75b36a 100644 --- a/phpBB/phpbb/tree/nestedset.php +++ b/phpBB/phpbb/tree/nestedset.php @@ -441,7 +441,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->column_left_id . ' = ' . $this->column_left_id . $diff . ', ' . $this->column_right_id . ' = ' . $this->column_right_id . $diff . ', - ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_parent_id . ' = ' . $current_parent_id, $new_parent_id, $this->column_parent_id) . ', + ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_parent_id . ' = ' . $current_parent_id, (string) $new_parent_id, $this->column_parent_id) . ', ' . $this->column_item_parents . " = '' WHERE " . $this->db->sql_in_set($this->column_item_id, $move_items) . ' ' . $this->get_sql_where('AND'); @@ -539,7 +539,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->column_left_id . ' = ' . $this->column_left_id . $diff . ', ' . $this->column_right_id . ' = ' . $this->column_right_id . $diff . ', - ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_item_id . ' = ' . $item_id, $new_parent_id, $this->column_parent_id) . ', + ' . $this->column_parent_id . ' = ' . $this->db->sql_case($this->column_item_id . ' = ' . $item_id, (string) $new_parent_id, $this->column_parent_id) . ', ' . $this->column_item_parents . " = '' WHERE " . $this->db->sql_in_set($this->column_item_id, $move_items) . ' ' . $this->get_sql_where('AND'); @@ -720,12 +720,12 @@ abstract class nestedset implements \phpbb\tree\tree_interface if ($set_subset_zero) { - $set_left_id = $this->db->sql_case($sql_subset_items, 0, $set_left_id); - $set_right_id = $this->db->sql_case($sql_subset_items, 0, $set_right_id); + $set_left_id = $this->db->sql_case($sql_subset_items, '0', $set_left_id); + $set_right_id = $this->db->sql_case($sql_subset_items, '0', $set_right_id); } $sql = 'UPDATE ' . $this->table_name . ' - SET ' . (($set_subset_zero) ? $this->column_parent_id . ' = ' . $this->db->sql_case($sql_subset_items, 0, $this->column_parent_id) . ',' : '') . ' + SET ' . (($set_subset_zero) ? $this->column_parent_id . ' = ' . $this->db->sql_case($sql_subset_items, '0', $this->column_parent_id) . ',' : '') . ' ' . $this->column_left_id . ' = ' . $set_left_id . ', ' . $this->column_right_id . ' = ' . $set_right_id . ' ' . ((!$set_subset_zero) ? ' WHERE ' . $sql_not_subset_items . ' ' . $this->get_sql_where('AND') : $this->get_sql_where('WHERE')); diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index bf4f10c15a..2a3e3995c0 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -765,11 +765,11 @@ class user extends \phpbb\session /** * Get option bit field from user options. * - * @param int $key option key, as defined in $keyoptions property. + * @param string $key option key, as defined in $keyoptions property. * @param int|false $data bit field value to use, or false to use $this->data['user_options'] * @return bool true if the option is set in the bit field, false otherwise */ - function optionget($key, $data = false) + function optionget(string $key, $data = false) { $var = ($data !== false) ? $data : $this->data['user_options']; return phpbb_optionget($this->keyoptions[$key], $var); diff --git a/psalm.xml b/psalm.xml index 1308223525..03c227ded8 100644 --- a/psalm.xml +++ b/psalm.xml @@ -20,6 +20,8 @@ + + From 5d5308965184fb2761cf411d6e745d66dd78acaa Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 30 Dec 2023 18:04:27 +0100 Subject: [PATCH 3/5] [ticket/17281] Fix some smaller issues PHPBB3-17281 --- phpBB/phpbb/template/base.php | 2 +- phpBB/phpbb/template/context.php | 4 ++-- phpBB/phpbb/template/template.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/template/base.php b/phpBB/phpbb/template/base.php index 314cdc4796..2cc71869aa 100644 --- a/phpBB/phpbb/template/base.php +++ b/phpBB/phpbb/template/base.php @@ -87,7 +87,7 @@ abstract class base implements template /** * {@inheritdoc} */ - public function assign_var($varname, $varval) + public function assign_var(string $varname, mixed $varval) { $this->context->assign_var($varname, $varval); diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index b510c88ad5..d952a84334 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -60,10 +60,10 @@ class context * Value can be a string, an integer or a boolean. * * @param string $varname Variable name - * @param bool|int|string $varval Value to assign to variable + * @param mixed $varval Value to assign to variable * @return true */ - public function assign_var(string $varname, bool|int|string $varval) + public function assign_var(string $varname, mixed $varval) { $this->rootref[$varname] = $varval; diff --git a/phpBB/phpbb/template/template.php b/phpBB/phpbb/template/template.php index c251513698..fef35de0c3 100644 --- a/phpBB/phpbb/template/template.php +++ b/phpBB/phpbb/template/template.php @@ -103,10 +103,10 @@ interface template * Value can be a string, an integer or a boolean. * * @param string $varname Variable name - * @param bool|int|string $varval Value to assign to variable + * @param mixed $varval Value to assign to variable * @return \phpbb\template\template $this */ - public function assign_var(string $varname, bool|int|string $varval); + public function assign_var(string $varname, mixed $varval); /** * Append text to the string value stored in a key. From e42b743b863d2213923c808c554c5cdd0805dbe8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 30 Dec 2023 20:58:54 +0100 Subject: [PATCH 4/5] [ticket/17281] Fix return type and ensure type correctness PHPBB3-17281 --- phpBB/phpbb/avatar/manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 18b198caa7..f4fc16ab52 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -190,7 +190,7 @@ class manager * @param array $row User data or group data * @param string $prefix Prefix of data keys (e.g. user), should not include the trailing underscore * - * @return array{string, string} User or group data with keys that have been + * @return array User or group data with keys that have been * stripped from the preceding "user_" or "group_" * Also the group id is prefixed with g, when the prefix group is removed. */ @@ -205,7 +205,7 @@ class manager $output = []; foreach ($row as $key => $value) { - $key = preg_replace("#^(?:{$prefix}_)#", '', $key); + $key = preg_replace("#^(?:{$prefix}_)#", '', (string) $key); $output[$key] = $value; } From c73e7bfe05bc463022a1f06b9986ddee122d7291 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 31 Dec 2023 15:08:37 +0100 Subject: [PATCH 5/5] [ticket/17281] Remove not needed suppress PHPBB3-17281 --- phpBB/phpbb/event/recursive_event_filter_iterator.php | 2 -- phpBB/phpbb/extension/provider.php | 2 -- phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php | 2 -- phpBB/phpbb/finder/recursive_path_iterator.php | 3 --- phpBB/phpbb/request/deactivated_super_global.php | 1 - 5 files changed, 10 deletions(-) diff --git a/phpBB/phpbb/event/recursive_event_filter_iterator.php b/phpBB/phpbb/event/recursive_event_filter_iterator.php index ed5277d5b3..f671c474d9 100644 --- a/phpBB/phpbb/event/recursive_event_filter_iterator.php +++ b/phpBB/phpbb/event/recursive_event_filter_iterator.php @@ -17,8 +17,6 @@ namespace phpbb\event; * This filter ignores directories and files starting with a dot. * It also skips some directories that do not contain events anyway, * such as e.g. files/, store/ and vendor/ -* -* @psalm-suppress MissingTemplateParam */ class recursive_event_filter_iterator extends \RecursiveFilterIterator { diff --git a/phpBB/phpbb/extension/provider.php b/phpBB/phpbb/extension/provider.php index 8432f956cb..221b1c933d 100644 --- a/phpBB/phpbb/extension/provider.php +++ b/phpBB/phpbb/extension/provider.php @@ -23,8 +23,6 @@ namespace phpbb\extension; * * Items could be anything, for example template paths or cron task names. * Derived classes completely define what the items are. -* -* @psalm-suppress MissingTemplateParam */ abstract class provider implements \IteratorAggregate { diff --git a/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php b/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php index 2a07638086..e4f9ea1d8a 100644 --- a/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php +++ b/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php @@ -19,8 +19,6 @@ namespace phpbb\finder; * This filter ignores directories starting with a dot. * When searching for php classes and template files of extensions * we don't need to look inside these directories. -* -* @psalm-suppress MissingTemplateParam */ class recursive_dot_prefix_filter_iterator extends \RecursiveFilterIterator { diff --git a/phpBB/phpbb/finder/recursive_path_iterator.php b/phpBB/phpbb/finder/recursive_path_iterator.php index 8a3418dd87..f93a240af2 100644 --- a/phpBB/phpbb/finder/recursive_path_iterator.php +++ b/phpBB/phpbb/finder/recursive_path_iterator.php @@ -15,9 +15,6 @@ declare(strict_types=1); namespace phpbb\finder; -/** - * @psalm-suppress MissingTemplateParam - */ class recursive_path_iterator extends \RecursiveIteratorIterator { /** diff --git a/phpBB/phpbb/request/deactivated_super_global.php b/phpBB/phpbb/request/deactivated_super_global.php index af4349d477..0ab19c5bb3 100644 --- a/phpBB/phpbb/request/deactivated_super_global.php +++ b/phpBB/phpbb/request/deactivated_super_global.php @@ -16,7 +16,6 @@ namespace phpbb\request; /** * Replacement for a superglobal (like $_GET or $_POST) which calls * trigger_error on all operations but isset, overloads the [] operator with SPL. -* @psalm-suppress MissingTemplateParam */ class deactivated_super_global implements \ArrayAccess, \Countable, \IteratorAggregate {