From 9a546c535c9f9c160dd4a40e07f07eb33c883ecb Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 13:51:45 +0100 Subject: [PATCH 01/42] [ticket/16955] Use common code for path iterator generation PHPBB3-16955 --- phpBB/develop/export_events_for_bbcode.php | 2 +- phpBB/develop/export_events_for_rst.php | 2 +- phpBB/develop/export_events_for_wiki.php | 2 +- phpBB/includes/acp/acp_language.php | 11 +---- phpBB/includes/functions_compatibility.php | 12 ++--- phpBB/phpbb/event/md_exporter.php | 9 +--- phpBB/phpbb/extension/manager.php | 9 ++-- phpBB/phpbb/finder/finder.php | 9 +--- .../recursive_dot_prefix_filter_iterator.php | 2 +- .../iterator/recursive_path_iterator.php | 47 +++++++++++++++++++ 10 files changed, 64 insertions(+), 41 deletions(-) rename phpBB/phpbb/{ => iterator}/recursive_dot_prefix_filter_iterator.php (96%) create mode 100644 phpBB/phpbb/iterator/recursive_path_iterator.php diff --git a/phpBB/develop/export_events_for_bbcode.php b/phpBB/develop/export_events_for_bbcode.php index 56709189c8..e30027bf94 100644 --- a/phpBB/develop/export_events_for_bbcode.php +++ b/phpBB/develop/export_events_for_bbcode.php @@ -65,7 +65,7 @@ require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx; require __DIR__ . '/../phpbb/event/rst_exporter.' . $phpEx; require __DIR__ . '/../includes/functions.' . $phpEx; require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx; -require __DIR__ . '/../phpbb/recursive_dot_prefix_filter_iterator.' . $phpEx; +require __DIR__ . '/../phpbb/iterator/recursive_dot_prefix_filter_iterator.' . $phpEx; switch ($action) { diff --git a/phpBB/develop/export_events_for_rst.php b/phpBB/develop/export_events_for_rst.php index d8cef7bf9f..908d4298d6 100644 --- a/phpBB/develop/export_events_for_rst.php +++ b/phpBB/develop/export_events_for_rst.php @@ -68,7 +68,7 @@ require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx; require __DIR__ . '/../phpbb/event/rst_exporter.' . $phpEx; require __DIR__ . '/../includes/functions.' . $phpEx; require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx; -require __DIR__ . '/../phpbb/recursive_dot_prefix_filter_iterator.' . $phpEx; +require __DIR__ . '/../phpbb/iterator/recursive_dot_prefix_filter_iterator.' . $phpEx; switch ($action) { diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index be16e5e7cd..128d6f3c57 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -67,7 +67,7 @@ require __DIR__ . '/../phpbb/event/php_exporter.' . $phpEx; require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx; require __DIR__ . '/../includes/functions.' . $phpEx; require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx; -require __DIR__ . '/../phpbb/recursive_dot_prefix_filter_iterator.' . $phpEx; +require __DIR__ . '/../phpbb/iterator/recursive_dot_prefix_filter_iterator.' . $phpEx; switch ($action) { diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php index a647128624..82a3e570e5 100644 --- a/phpBB/includes/acp/acp_language.php +++ b/phpBB/includes/acp/acp_language.php @@ -220,15 +220,7 @@ class acp_language { try { - $iterator = new \RecursiveIteratorIterator( - new \phpbb\recursive_dot_prefix_filter_iterator( - new \RecursiveDirectoryIterator( - $this->phpbb_root_path . 'language/' . $this->config['default_lang'] . '/', - \FilesystemIterator::SKIP_DOTS - ) - ), - \RecursiveIteratorIterator::LEAVES_ONLY - ); + $iterator = new \phpbb\iterator\recursive_path_iterator($this->phpbb_root_path . 'language/' . $this->config['default_lang'] . '/'); } catch (\Exception $e) { @@ -237,7 +229,6 @@ class acp_language foreach ($iterator as $file_info) { - /** @var \RecursiveDirectoryIterator $file_info */ $relative_path = $iterator->getInnerIterator()->getSubPathname(); $relative_path = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path); diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php index 8f9bac5b82..0783035e6c 100644 --- a/phpBB/includes/functions_compatibility.php +++ b/phpBB/includes/functions_compatibility.php @@ -646,14 +646,10 @@ function phpbb_email_hash($email) */ function phpbb_load_extensions_autoloaders($phpbb_root_path) { - $iterator = new \RecursiveIteratorIterator( - new \phpbb\recursive_dot_prefix_filter_iterator( - new \RecursiveDirectoryIterator( - $phpbb_root_path . 'ext/', - \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS - ) - ), - \RecursiveIteratorIterator::SELF_FIRST + $iterator = new \phpbb\iterator\recursive_path_iterator( + $phpbb_root_path . 'ext/', + \RecursiveIteratorIterator::SELF_FIRST, + \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS ); $iterator->setMaxDepth(2); diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index af5eed7867..8ddc213020 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -658,13 +658,8 @@ class md_exporter { try { - $iterator = new \RecursiveIteratorIterator( - new \phpbb\recursive_dot_prefix_filter_iterator( - new \RecursiveDirectoryIterator( - $dir, - \FilesystemIterator::SKIP_DOTS - ) - ), + $iterator = new \phpbb\iterator\recursive_path_iterator( + $dir, \RecursiveIteratorIterator::SELF_FIRST ); } diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index c012d9a989..0590adfc98 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -380,11 +380,10 @@ class manager return $available; } - $iterator = new \RecursiveIteratorIterator( - new \phpbb\recursive_dot_prefix_filter_iterator( - new \RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/', \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::FOLLOW_SYMLINKS) - ), - \RecursiveIteratorIterator::SELF_FIRST + $iterator = new \phpbb\iterator\recursive_path_iterator( + $this->phpbb_root_path . 'ext/', + \RecursiveIteratorIterator::SELF_FIRST, + \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::FOLLOW_SYMLINKS ); $iterator->setMaxDepth(2); diff --git a/phpBB/phpbb/finder/finder.php b/phpBB/phpbb/finder/finder.php index 6b0baef19f..bcd1c355c0 100644 --- a/phpBB/phpbb/finder/finder.php +++ b/phpBB/phpbb/finder/finder.php @@ -486,13 +486,8 @@ class finder if (is_dir($path)) { - $iterator = new \RecursiveIteratorIterator( - new \phpbb\recursive_dot_prefix_filter_iterator( - new \RecursiveDirectoryIterator( - $path, - \FilesystemIterator::SKIP_DOTS - ) - ), + $iterator = new \phpbb\iterator\recursive_path_iterator( + $path, \RecursiveIteratorIterator::SELF_FIRST ); diff --git a/phpBB/phpbb/recursive_dot_prefix_filter_iterator.php b/phpBB/phpbb/iterator/recursive_dot_prefix_filter_iterator.php similarity index 96% rename from phpBB/phpbb/recursive_dot_prefix_filter_iterator.php rename to phpBB/phpbb/iterator/recursive_dot_prefix_filter_iterator.php index 1446551b8b..4549e03e8e 100644 --- a/phpBB/phpbb/recursive_dot_prefix_filter_iterator.php +++ b/phpBB/phpbb/iterator/recursive_dot_prefix_filter_iterator.php @@ -11,7 +11,7 @@ * */ -namespace phpbb; +namespace phpbb\iterator; /** * Class recursive_dot_prefix_filter_iterator diff --git a/phpBB/phpbb/iterator/recursive_path_iterator.php b/phpBB/phpbb/iterator/recursive_path_iterator.php new file mode 100644 index 0000000000..d120c451fd --- /dev/null +++ b/phpBB/phpbb/iterator/recursive_path_iterator.php @@ -0,0 +1,47 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +declare(strict_types=1); + +namespace phpbb\iterator; + +class recursive_path_iterator extends \RecursiveIteratorIterator +{ + /** + * Constructor + * + * @param string $path Path to iterate over + * @param int $mode Iterator mode + * @param int $flags Flags + */ + public function __construct(string $path, int $mode = self::LEAVES_ONLY, int $flags = \FilesystemIterator::SKIP_DOTS) + { + parent::__construct( + new recursive_dot_prefix_filter_iterator(new \RecursiveDirectoryIterator($path, $flags)), + \RecursiveIteratorIterator::SELF_FIRST + ); + } + + /** + * Get inner iterator + * + * @return recursive_dot_prefix_filter_iterator + */ + public function getInnerIterator(): \RecursiveIterator + { + $inner_iterator = parent::getInnerIterator(); + + assert($inner_iterator instanceof recursive_dot_prefix_filter_iterator); + return $inner_iterator; + } +} From 160510dab360054750404da04c05125a9cc4b50f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 13:53:46 +0100 Subject: [PATCH 02/42] [ticket/16955] Update psalm and improve config & bootstrap PHPBB3-16955 --- build/psalm_bootstrap.php | 4 ++++ phpBB/composer.lock | 24 ++++++++++++------------ psalm.xml | 5 +++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/build/psalm_bootstrap.php b/build/psalm_bootstrap.php index 419a332b68..4d5a3ea85a 100644 --- a/build/psalm_bootstrap.php +++ b/build/psalm_bootstrap.php @@ -38,6 +38,10 @@ require_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx; require_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx; require_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx; require_once $phpbb_root_path . 'includes/functions_user.' . $phpEx; +require_once $phpbb_root_path . 'includes/sphinxapi.' . $phpEx; +require_once $phpbb_root_path . 'includes/diff/diff.' . $phpEx; +require_once $phpbb_root_path . 'includes/diff/engine.' . $phpEx; +require_once $phpbb_root_path . 'includes/compatibility_globals.' . $phpEx; $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', $phpbb_root_path . 'phpbb/', "php"); $phpbb_class_loader->register(); diff --git a/phpBB/composer.lock b/phpBB/composer.lock index c738cbe84a..5361ee8f9a 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -6979,16 +6979,16 @@ }, { "name": "psalm/plugin-symfony", - "version": "v3.1.9", + "version": "v3.1.10", "source": { "type": "git", "url": "https://github.com/psalm/psalm-plugin-symfony.git", - "reference": "b9511a3c4dd67131d2ae55f6d12b6c28ce56a561" + "reference": "5dca17839a6d48766ac760b8aa6d1f6d12759b28" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/psalm/psalm-plugin-symfony/zipball/b9511a3c4dd67131d2ae55f6d12b6c28ce56a561", - "reference": "b9511a3c4dd67131d2ae55f6d12b6c28ce56a561", + "url": "https://api.github.com/repos/psalm/psalm-plugin-symfony/zipball/5dca17839a6d48766ac760b8aa6d1f6d12759b28", + "reference": "5dca17839a6d48766ac760b8aa6d1f6d12759b28", "shasum": "" }, "require": { @@ -7038,9 +7038,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.9" + "source": "https://github.com/psalm/psalm-plugin-symfony/tree/v3.1.10" }, - "time": "2022-09-12T13:01:42+00:00" + "time": "2022-10-22T13:09:05+00:00" }, { "name": "sebastian/cli-parser", @@ -8727,16 +8727,16 @@ }, { "name": "vimeo/psalm", - "version": "4.29.0", + "version": "4.30.0", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "7ec5ffbd5f68ae03782d7fd33fff0c45a69f95b3" + "reference": "d0bc6e25d89f649e4f36a534f330f8bb4643dd69" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/7ec5ffbd5f68ae03782d7fd33fff0c45a69f95b3", - "reference": "7ec5ffbd5f68ae03782d7fd33fff0c45a69f95b3", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/d0bc6e25d89f649e4f36a534f330f8bb4643dd69", + "reference": "d0bc6e25d89f649e4f36a534f330f8bb4643dd69", "shasum": "" }, "require": { @@ -8829,9 +8829,9 @@ ], "support": { "issues": "https://github.com/vimeo/psalm/issues", - "source": "https://github.com/vimeo/psalm/tree/4.29.0" + "source": "https://github.com/vimeo/psalm/tree/4.30.0" }, - "time": "2022-10-11T17:09:17+00:00" + "time": "2022-11-06T20:37:08+00:00" }, { "name": "webmozart/assert", diff --git a/psalm.xml b/psalm.xml index b28f550d48..02160bcadf 100644 --- a/psalm.xml +++ b/psalm.xml @@ -14,5 +14,10 @@ + + + + + From ea07e4946f16e01753ae42ba7dbc36a512c0abfb Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 13:54:42 +0100 Subject: [PATCH 03/42] [ticket/16955] Correct docblocks in diff engine PHPBB3-16955 --- phpBB/includes/diff/diff.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/diff/diff.php b/phpBB/includes/diff/diff.php index d5d0e3e3f0..bed16285a1 100644 --- a/phpBB/includes/diff/diff.php +++ b/phpBB/includes/diff/diff.php @@ -46,8 +46,8 @@ class diff /** * Computes diffs between sequences of strings. * - * @param array &$from_content An array of strings. Typically these are lines from a file. - * @param array &$to_content An array of strings. + * @param array|string &$from_content An array of strings. Typically these are lines from a file. + * @param array|string &$to_content An array of strings. * @param bool $preserve_cr If true, \r is replaced by a new line in the diff output */ function __construct(&$from_content, &$to_content, $preserve_cr = true) @@ -498,9 +498,9 @@ class diff3 extends diff /** * Computes diff between 3 sequences of strings. * - * @param array &$orig The original lines to use. - * @param array &$final1 The first version to compare to. - * @param array &$final2 The second version to compare to. + * @param array|string &$orig The original lines to use. + * @param array|string &$final1 The first version to compare to. + * @param array|string &$final2 The second version to compare to. * @param bool $preserve_cr If true, \r\n and bare \r are replaced by a new line * in the diff output */ From cd026245fe1c1b8e7f135dbdf5de3eef36ec907b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 13:55:36 +0100 Subject: [PATCH 04/42] [ticket/16955] Improve minor docblock quirks PHPBB3-16955 --- phpBB/includes/functions_content.php | 4 ++-- phpBB/includes/functions_display.php | 2 +- phpBB/phpbb/db/driver/driver_interface.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index f95d092c5b..783fa67044 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1527,8 +1527,8 @@ function truncate_string($string, $max_length = 60, $max_store_length = 255, $al * @param int $user_id The users id * @param string $username The users name * @param string $username_colour The users colour -* @param string $guest_username optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. -* @param string $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} +* @param string|false $guest_username optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. +* @param string|false $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} * * @return string A string consisting of what is wanted based on $mode. */ diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 6b8f812afa..9a1f33db37 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1490,7 +1490,7 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, * Get user rank title and image * * @param array $user_data the current stored users data -* @param int $user_posts the users number of posts +* @param int|false $user_posts the users number of posts or false if guest * * @return array An associative array containing the rank title (title), the rank image as full img tag (img) and the rank image source (img_src) * diff --git a/phpBB/phpbb/db/driver/driver_interface.php b/phpBB/phpbb/db/driver/driver_interface.php index e269fac585..6d95f61c16 100644 --- a/phpBB/phpbb/db/driver/driver_interface.php +++ b/phpBB/phpbb/db/driver/driver_interface.php @@ -291,7 +291,7 @@ interface driver_interface /** * Get last inserted id after insert statement * - * @return string Autoincrement value of the last inserted row + * @return int|false Autoincrement value of the last inserted row */ public function sql_nextid(); From c4d3e1aa7b882a41a73d52d31f4b7462657e86f5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:07:53 +0100 Subject: [PATCH 05/42] [ticket/16955] Resolve psalm issues in di files PHPBB3-16955 --- build/psalm_bootstrap.php | 4 ++++ phpBB/phpbb/di/container_builder.php | 3 ++- phpBB/phpbb/di/extension/config.php | 4 ++-- phpBB/phpbb/di/ordered_service_collection.php | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/build/psalm_bootstrap.php b/build/psalm_bootstrap.php index 4d5a3ea85a..4fc5628459 100644 --- a/build/psalm_bootstrap.php +++ b/build/psalm_bootstrap.php @@ -45,3 +45,7 @@ require_once $phpbb_root_path . 'includes/compatibility_globals.' . $phpEx; $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', $phpbb_root_path . 'phpbb/', "php"); $phpbb_class_loader->register(); + +class phpbb_cache_container extends \Symfony\Component\DependencyInjection\Container +{ +} diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 20e87e7660..b9dc8bba63 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -46,7 +46,7 @@ class container_builder /** * The container under construction * - * @var ContainerBuilder + * @var \phpbb_cache_container|ContainerBuilder */ protected $container; @@ -449,6 +449,7 @@ class container_builder $ext_container->register('cache.driver', '\\phpbb\\cache\\driver\\dummy'); $ext_container->compile(); + /** @var \phpbb\config\config $config */ $config = $ext_container->get('config'); if (@is_file($this->phpbb_root_path . $config['exts_composer_vendor_dir'] . '/autoload.php')) { diff --git a/phpBB/phpbb/di/extension/config.php b/phpBB/phpbb/di/extension/config.php index 6274f0f020..775de380ec 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -32,12 +32,12 @@ class config extends Extension /** * Loads a specific configuration. * - * @param array $config An array of configuration values + * @param array $configs An array of configuration values * @param ContainerBuilder $container A ContainerBuilder instance * * @throws \InvalidArgumentException When provided tag is not defined in this extension */ - public function load(array $config, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container) { $parameters = array( 'core.adm_relative_path' => $this->config_php->get('phpbb_adm_relative_path') ? $this->config_php->get('phpbb_adm_relative_path') : 'adm/', diff --git a/phpBB/phpbb/di/ordered_service_collection.php b/phpBB/phpbb/di/ordered_service_collection.php index 046012ae5b..57b674b986 100644 --- a/phpBB/phpbb/di/ordered_service_collection.php +++ b/phpBB/phpbb/di/ordered_service_collection.php @@ -85,13 +85,13 @@ class ordered_service_collection extends service_collection /** * Adds a service ID to the collection * - * @param string $service_id + * @param string $name * @param int $order */ - public function add($service_id, $order = 0) + public function add($name, $order = 0) { $order = (int) $order; - $this->service_ids[$order][] = $service_id; + $this->service_ids[$order][] = $name; $this->is_ordered = false; } From d9c179f9efd46b50a518eca28d46adde75c7570d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:41:18 +0100 Subject: [PATCH 06/42] [ticket/16955] Clean up group related classes for psalm PHPBB3-16955 --- phpBB/phpbb/group/helper.php | 1 + phpBB/phpbb/groupposition/legend.php | 19 ++++++++------ phpBB/phpbb/groupposition/teampage.php | 34 ++++++++++++++++---------- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/phpBB/phpbb/group/helper.php b/phpBB/phpbb/group/helper.php index 92dd71384f..c56c08c0a4 100644 --- a/phpBB/phpbb/group/helper.php +++ b/phpBB/phpbb/group/helper.php @@ -119,6 +119,7 @@ class helper public function get_name_string($mode, $group_id, $group_name, $group_colour = '', $custom_profile_url = false) { $s_is_bots = ($group_name === 'BOTS'); + $group_name_string = null; // This switch makes sure we only run code required for the mode switch ($mode) diff --git a/phpBB/phpbb/groupposition/legend.php b/phpBB/phpbb/groupposition/legend.php index 9dcdb10ab6..fb4ea44af6 100644 --- a/phpBB/phpbb/groupposition/legend.php +++ b/phpBB/phpbb/groupposition/legend.php @@ -47,8 +47,9 @@ class legend implements \phpbb\groupposition\groupposition_interface * Returns the group_legend for a given group, if the group exists. * * @param int $group_id group_id of the group to be selected + * * @return int position of the group - * @throws \phpbb\groupposition\exception + * @throws exception */ public function get_group_value($group_id) { @@ -62,7 +63,7 @@ class legend implements \phpbb\groupposition\groupposition_interface if ($current_value === false) { // Group not found. - throw new \phpbb\groupposition\exception('NO_GROUP'); + throw new exception('NO_GROUP'); } return (int) $current_value; @@ -212,11 +213,13 @@ class legend implements \phpbb\groupposition\groupposition_interface } /** - * Get group type language var - * - * @param int $group_type group_type from the groups-table - * @return string name of the language variable for the given group-type. - */ + * Get group type language var + * + * @param int $group_type group_type from the groups-table + * + * @return string name of the language variable for the given group-type. + * @throws exception If invalid group type is supplied + */ public static function group_type_language($group_type) { switch ($group_type) @@ -231,6 +234,8 @@ class legend implements \phpbb\groupposition\groupposition_interface return 'GROUP_SPECIAL'; case GROUP_FREE: return 'GROUP_OPEN'; + default: + throw new exception('NO_GROUP'); } } } diff --git a/phpBB/phpbb/groupposition/teampage.php b/phpBB/phpbb/groupposition/teampage.php index fc6373b47b..2358cc9528 100644 --- a/phpBB/phpbb/groupposition/teampage.php +++ b/phpBB/phpbb/groupposition/teampage.php @@ -58,8 +58,9 @@ class teampage implements \phpbb\groupposition\groupposition_interface * Returns the teampage position for a given group, if the group exists. * * @param int $group_id group_id of the group to be selected + * * @return int position of the group - * @throws \phpbb\groupposition\exception + * @throws exception */ public function get_group_value($group_id) { @@ -76,7 +77,7 @@ class teampage implements \phpbb\groupposition\groupposition_interface if ($row === false) { // Group not found. - throw new \phpbb\groupposition\exception('NO_GROUP'); + throw new exception('NO_GROUP'); } return (int) $row['teampage_position']; @@ -86,8 +87,9 @@ class teampage implements \phpbb\groupposition\groupposition_interface * Returns the row for a given group, if the group exists. * * @param int $group_id group_id of the group to be selected + * * @return array Data row of the group - * @throws \phpbb\groupposition\exception + * @throws exception */ public function get_group_values($group_id) { @@ -104,7 +106,7 @@ class teampage implements \phpbb\groupposition\groupposition_interface if ($row === false) { // Group not found. - throw new \phpbb\groupposition\exception('NO_GROUP'); + throw new exception('NO_GROUP'); } return $row; @@ -114,8 +116,9 @@ class teampage implements \phpbb\groupposition\groupposition_interface * Returns the teampage position for a given teampage item, if the item exists. * * @param int $teampage_id Teampage_id of the selected item + * * @return int Teampage position of the item - * @throws \phpbb\groupposition\exception + * @throws exception */ public function get_teampage_value($teampage_id) { @@ -129,7 +132,7 @@ class teampage implements \phpbb\groupposition\groupposition_interface if ($current_value === false) { // Group not found. - throw new \phpbb\groupposition\exception('NO_GROUP'); + throw new exception('NO_GROUP'); } return (int) $current_value; @@ -139,8 +142,9 @@ class teampage implements \phpbb\groupposition\groupposition_interface * Returns the teampage row for a given teampage item, if the item exists. * * @param int $teampage_id Teampage_id of the selected item + * * @return array Teampage row of the item - * @throws \phpbb\groupposition\exception + * @throws exception */ public function get_teampage_values($teampage_id) { @@ -154,7 +158,7 @@ class teampage implements \phpbb\groupposition\groupposition_interface if ($row === false) { // Group not found. - throw new \phpbb\groupposition\exception('NO_GROUP'); + throw new exception('NO_GROUP'); } return $row; @@ -565,11 +569,13 @@ class teampage implements \phpbb\groupposition\groupposition_interface } /** - * Get group type language var - * - * @param int $group_type group_type from the groups-table - * @return string name of the language variable for the given group-type. - */ + * Get group type language var + * + * @param int $group_type group_type from the groups-table + * + * @return string name of the language variable for the given group-type. + * @throws exception If invalid group type is supplied + */ public static function group_type_language($group_type) { switch ($group_type) @@ -584,6 +590,8 @@ class teampage implements \phpbb\groupposition\groupposition_interface return 'GROUP_SPECIAL'; case GROUP_FREE: return 'GROUP_OPEN'; + default: + throw new exception('NO_GROUP'); } } } From 40e8a737c3c3b1e593c79be5de00fa7ca9b474c7 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:42:23 +0100 Subject: [PATCH 07/42] [ticket/16955] Clean up installer classes for psalm PHPBB3-16955 --- .../install/console/command/install/config/show.php | 10 ++++++---- .../console/command/install/config/validate.php | 2 +- .../phpbb/install/console/command/install/install.php | 2 +- .../install/console/command/update/config/show.php | 10 ++++++---- .../install/console/command/update/config/validate.php | 2 +- phpBB/phpbb/install/controller/install.php | 1 + phpBB/phpbb/install/database_task.php | 10 +++++----- .../install/event/kernel_exception_subscriber.php | 8 +++----- phpBB/phpbb/install/helper/container_factory.php | 4 ++-- .../helper/file_updater/compression_file_updater.php | 7 +++++-- .../phpbb/install/helper/iohandler/ajax_iohandler.php | 6 ++++-- phpBB/phpbb/install/helper/iohandler/cli_iohandler.php | 4 ++-- phpBB/phpbb/install/helper/iohandler/factory.php | 9 ++++----- phpBB/phpbb/install/helper/update_helper.php | 1 + phpBB/phpbb/install/installer.php | 1 + .../install/module/install_data/task/add_languages.php | 2 +- .../module/install_finish/task/install_extensions.php | 6 +++--- .../module/obtain_data/task/obtain_update_files.php | 1 + .../install/module/requirements/task/check_update.php | 1 + .../module/update_database/task/update_extensions.php | 6 +++--- .../module/update_filesystem/task/update_files.php | 2 +- phpBB/phpbb/install/module_base.php | 1 + 22 files changed, 54 insertions(+), 42 deletions(-) diff --git a/phpBB/phpbb/install/console/command/install/config/show.php b/phpBB/phpbb/install/console/command/install/config/show.php index b6c11956fe..58ad7397da 100644 --- a/phpBB/phpbb/install/console/command/install/config/show.php +++ b/phpBB/phpbb/install/console/command/install/config/show.php @@ -73,7 +73,7 @@ class show extends \phpbb\console\command\command * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * - * @return null + * @return int 0 if everything went fine, or a non-zero exit code */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -90,7 +90,7 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message(array('MISSING_FILE', $config_file)); - return; + return 1; } try @@ -101,7 +101,7 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_YAML_FILE'); - return; + return 1; } $processor = new Processor(); @@ -115,9 +115,11 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage()); - return; + return 1; } $style->block(Yaml::dump(array('installer' => $config), 10, 4, true, false)); + + return 0; } } diff --git a/phpBB/phpbb/install/console/command/install/config/validate.php b/phpBB/phpbb/install/console/command/install/config/validate.php index b48a1acbd4..0b8a28beaa 100644 --- a/phpBB/phpbb/install/console/command/install/config/validate.php +++ b/phpBB/phpbb/install/console/command/install/config/validate.php @@ -73,7 +73,7 @@ class validate extends \phpbb\console\command\command * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * - * @return null + * @return int 0 if everything went fine, or a non-zero exit code */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/phpBB/phpbb/install/console/command/install/install.php b/phpBB/phpbb/install/console/command/install/install.php index 980586cb0e..e50eeeb5bc 100644 --- a/phpBB/phpbb/install/console/command/install/install.php +++ b/phpBB/phpbb/install/console/command/install/install.php @@ -92,7 +92,7 @@ class install extends \phpbb\console\command\command * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * - * @return null + * @return int 0 if everything went fine, or a non-zero exit code */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/phpBB/phpbb/install/console/command/update/config/show.php b/phpBB/phpbb/install/console/command/update/config/show.php index e462763b5d..138c5cae28 100644 --- a/phpBB/phpbb/install/console/command/update/config/show.php +++ b/phpBB/phpbb/install/console/command/update/config/show.php @@ -73,7 +73,7 @@ class show extends \phpbb\console\command\command * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * - * @return null + * @return int 0 if everything went fine, or a non-zero exit code */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -90,7 +90,7 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message(array('MISSING_FILE', $config_file)); - return; + return 1; } try @@ -101,7 +101,7 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_YAML_FILE'); - return; + return 1; } $processor = new Processor(); @@ -115,9 +115,11 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage()); - return; + return 1; } $style->block(Yaml::dump(array('updater' => $config), 10, 4, true, false)); + + return 0; } } diff --git a/phpBB/phpbb/install/console/command/update/config/validate.php b/phpBB/phpbb/install/console/command/update/config/validate.php index 18de5eab46..8a0d963ac2 100644 --- a/phpBB/phpbb/install/console/command/update/config/validate.php +++ b/phpBB/phpbb/install/console/command/update/config/validate.php @@ -73,7 +73,7 @@ class validate extends \phpbb\console\command\command * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * - * @return null + * @return int 0 if everything went fine, or a non-zero exit code */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/phpBB/phpbb/install/controller/install.php b/phpBB/phpbb/install/controller/install.php index 92506872a3..47acc2953f 100644 --- a/phpBB/phpbb/install/controller/install.php +++ b/phpBB/phpbb/install/controller/install.php @@ -99,6 +99,7 @@ class install * @return Response|StreamedResponse * * @throws http_exception When phpBB is already installed + * @psalm-suppress InvalidNullableReturnType */ public function handle() { diff --git a/phpBB/phpbb/install/database_task.php b/phpBB/phpbb/install/database_task.php index 81864773c5..758e511c1a 100644 --- a/phpBB/phpbb/install/database_task.php +++ b/phpBB/phpbb/install/database_task.php @@ -93,9 +93,9 @@ abstract class database_task extends task_base * * @param string $sql The SQL. * - * @return DriverStmt|Statement The prepared statement object. + * @return Statement|null The prepared statement object or null if preparing failed */ - protected function create_prepared_stmt(string $sql) + protected function create_prepared_stmt(string $sql): ?Statement { try { @@ -153,13 +153,13 @@ abstract class database_task extends task_base /** * Returns the last insert ID. * - * @return string|null The last insert ID. + * @return int|null The last insert ID. */ - protected function get_last_insert_id() : ?string + protected function get_last_insert_id() : ?int { try { - return $this->conn->lastInsertId(); + return (int) $this->conn->lastInsertId(); } catch (Exception $e) { diff --git a/phpBB/phpbb/install/event/kernel_exception_subscriber.php b/phpBB/phpbb/install/event/kernel_exception_subscriber.php index dd0d15c72e..79a5bbc8b9 100644 --- a/phpBB/phpbb/install/event/kernel_exception_subscriber.php +++ b/phpBB/phpbb/install/event/kernel_exception_subscriber.php @@ -113,14 +113,12 @@ class kernel_exception_subscriber implements EventSubscriberInterface } /** - * Returns an array of events the object is subscribed to - * - * @return array Array of events the object is subscribed to + * {@inheritDoc} */ public static function getSubscribedEvents() { - return array( + return [ KernelEvents::EXCEPTION => 'on_kernel_exception', - ); + ]; } } diff --git a/phpBB/phpbb/install/helper/container_factory.php b/phpBB/phpbb/install/helper/container_factory.php index e689e44cde..b5869b67d0 100644 --- a/phpBB/phpbb/install/helper/container_factory.php +++ b/phpBB/phpbb/install/helper/container_factory.php @@ -75,7 +75,7 @@ class container_factory * * @param null|string $service_name Name of the service to return * - * @return \Symfony\Component\DependencyInjection\ContainerInterface|Object phpBB's dependency injection container + * @return \Symfony\Component\DependencyInjection\ContainerInterface|object|null phpBB's dependency injection container * or the service specified in $service_name * * @throws cannot_build_container_exception When container cannot be built @@ -91,7 +91,7 @@ class container_factory $this->build_container(); } - return ($service_name === null) ? $this->container : $this->container->get($service_name); + return $service_name === null ? $this->container : $this->container->get($service_name); } /** diff --git a/phpBB/phpbb/install/helper/file_updater/compression_file_updater.php b/phpBB/phpbb/install/helper/file_updater/compression_file_updater.php index c1044a3a1f..6e4fc2a845 100644 --- a/phpBB/phpbb/install/helper/file_updater/compression_file_updater.php +++ b/phpBB/phpbb/install/helper/file_updater/compression_file_updater.php @@ -21,7 +21,7 @@ use phpbb\install\helper\update_helper; class compression_file_updater implements file_updater_interface { /** - * @var \compress|null + * @var \compress_zip|\compress_tar|null */ protected $compress; @@ -86,7 +86,10 @@ class compression_file_updater implements file_updater_interface */ public function close() { - $this->compress->close(); + if ($this->compress !== null) + { + $this->compress->close(); + } } /** diff --git a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php index c235b8557a..06695f5057 100644 --- a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php +++ b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php @@ -82,7 +82,7 @@ class ajax_iohandler extends iohandler_base protected $redirect_url; /** - * @var resource + * @var resource|closed-resource */ protected $file_lock_pointer; @@ -235,7 +235,9 @@ class ajax_iohandler extends iohandler_base 'form_install' => 'installer_form.html', )); - return $this->template->assign_display('form_install'); + $compiled_template = $this->template->assign_display('form_install'); + + return is_string($compiled_template) ? $compiled_template : ''; } /** diff --git a/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php b/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php index 9553b11d34..5485fb3bfc 100644 --- a/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php +++ b/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php @@ -188,11 +188,11 @@ class cli_iohandler extends iohandler_base /** * {@inheritdoc */ - public function add_success_message($error_title, $error_description = false) + public function add_success_message($success_title, $success_description = false) { $this->io->newLine(); - $message = $this->translate_message($error_title, $error_description); + $message = $this->translate_message($success_title, $success_description); $message_string = $message['title'] . (!empty($message['description']) ? "\n" . $message['description'] : ''); $this->io->success($message_string); diff --git a/phpBB/phpbb/install/helper/iohandler/factory.php b/phpBB/phpbb/install/helper/iohandler/factory.php index 5ea1b93398..56503efdbd 100644 --- a/phpBB/phpbb/install/helper/iohandler/factory.php +++ b/phpBB/phpbb/install/helper/iohandler/factory.php @@ -52,7 +52,7 @@ class factory /** * Factory getter for iohandler * - * @return \phpbb\install\helper\iohandler\iohandler_interface + * @return \phpbb\install\helper\iohandler\iohandler_interface|null * * @throws iohandler_not_implemented_exception * When the specified iohandler_interface does not exists @@ -63,17 +63,16 @@ class factory { case 'ajax': return $this->container->get('installer.helper.iohandler_ajax'); - break; + case 'nojs': // @todo replace this return $this->container->get('installer.helper.iohandler_ajax'); - break; + case 'cli': return $this->container->get('installer.helper.iohandler_cli'); - break; + default: throw new iohandler_not_implemented_exception(); - break; } } } diff --git a/phpBB/phpbb/install/helper/update_helper.php b/phpBB/phpbb/install/helper/update_helper.php index a00731d317..41a9bca206 100644 --- a/phpBB/phpbb/install/helper/update_helper.php +++ b/phpBB/phpbb/install/helper/update_helper.php @@ -89,6 +89,7 @@ class update_helper * @param string $version_number2 * @param string|null $operator * @return int|bool The returned value is identical to the PHP build-in function version_compare() + * @psalm-suppress InvalidNullableReturnType, NullableReturnStatement */ public function phpbb_version_compare($version_number1, $version_number2, $operator = null) { diff --git a/phpBB/phpbb/install/installer.php b/phpBB/phpbb/install/installer.php index 08906d7830..26c1c8a0f6 100644 --- a/phpBB/phpbb/install/installer.php +++ b/phpBB/phpbb/install/installer.php @@ -179,6 +179,7 @@ class installer try { + /** @psalm-suppress InvalidTemplateParam */ $iterator = $this->installer_modules->getIterator(); if ($module_index < $iterator->count()) diff --git a/phpBB/phpbb/install/module/install_data/task/add_languages.php b/phpBB/phpbb/install/module/install_data/task/add_languages.php index e8722d8987..3e56d3f69e 100644 --- a/phpBB/phpbb/install/module/install_data/task/add_languages.php +++ b/phpBB/phpbb/install/module/install_data/task/add_languages.php @@ -102,7 +102,7 @@ class add_languages extends database_task ]); $installed_languages = $this->config->get('installed_languages', []); - array_push($installed_languages, (int) $this->get_last_insert_id()); + $installed_languages[] = (int) $this->get_last_insert_id(); $this->config->set('installed_languages', $installed_languages); } diff --git a/phpBB/phpbb/install/module/install_finish/task/install_extensions.php b/phpBB/phpbb/install/module/install_finish/task/install_extensions.php index 5f915c56f3..019553053f 100644 --- a/phpBB/phpbb/install/module/install_finish/task/install_extensions.php +++ b/phpBB/phpbb/install/module/install_finish/task/install_extensions.php @@ -42,7 +42,7 @@ class install_extensions extends database_task protected $iohandler; /** - * @var db + * @var \phpbb\config\config */ protected $config; @@ -106,9 +106,9 @@ class install_extensions extends database_task // Make sure asset version exists in config. Otherwise we might try to // insert the assets_version setting into the database and cause a // duplicate entry error. - if (!isset($this->config['assets_version'])) + if (!$this->config->offsetExists('assets_version')) { - $this->config['assets_version'] = 0; + $this->config->offsetSet('assets_version', 0); } parent::__construct( diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_update_files.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_files.php index b6dea1ca30..24581dda4c 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_update_files.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_update_files.php @@ -75,6 +75,7 @@ class obtain_update_files extends task_base // The file should be checked in the requirements, so we assume that it exists $update_info_file = $this->phpbb_root_path . 'install/update/index.' . $this->php_ext; include($update_info_file); + /** @var array $update_info */ $info = (empty($update_info) || !is_array($update_info)) ? false : $update_info; // If the file is invalid, abort mission diff --git a/phpBB/phpbb/install/module/requirements/task/check_update.php b/phpBB/phpbb/install/module/requirements/task/check_update.php index c15e6eafe2..2bd1841b3d 100644 --- a/phpBB/phpbb/install/module/requirements/task/check_update.php +++ b/phpBB/phpbb/install/module/requirements/task/check_update.php @@ -137,6 +137,7 @@ class check_update extends task_base // Recover version numbers $update_info = array(); @include($this->phpbb_root_path . 'install/update/index.' . $this->php_ext); + /** @var array|false $info */ $info = (empty($update_info) || !is_array($update_info)) ? false : $update_info; $update_version = false; diff --git a/phpBB/phpbb/install/module/update_database/task/update_extensions.php b/phpBB/phpbb/install/module/update_database/task/update_extensions.php index 4fe065fcb2..e47d23d052 100644 --- a/phpBB/phpbb/install/module/update_database/task/update_extensions.php +++ b/phpBB/phpbb/install/module/update_database/task/update_extensions.php @@ -45,7 +45,7 @@ class update_extensions extends task_base protected $update_helper; /** - * @var \phpbb\config\db + * @var \phpbb\config\config */ protected $config; @@ -111,9 +111,9 @@ class update_extensions extends task_base // Make sure asset version exists in config. Otherwise we might try to // insert the assets_version setting into the database and cause a // duplicate entry error. - if (!isset($this->config['assets_version'])) + if (!$this->config->offsetExists('assets_version')) { - $this->config['assets_version'] = 0; + $this->config->offsetSet('assets_version', 0); } parent::__construct(true); diff --git a/phpBB/phpbb/install/module/update_filesystem/task/update_files.php b/phpBB/phpbb/install/module/update_filesystem/task/update_files.php index b3325b93ce..49f76a5048 100644 --- a/phpBB/phpbb/install/module/update_filesystem/task/update_files.php +++ b/phpBB/phpbb/install/module/update_filesystem/task/update_files.php @@ -224,7 +224,7 @@ class update_files extends task_base } $file_updater_method = $this->installer_config->get('file_update_method', ''); - if ($file_updater_method === 'compression' || $file_updater_method === 'ftp') + if ($file_updater_method === 'compression' || $file_updater_method === 'ftp' && method_exists($this->file_updater, 'close')) { $this->file_updater->close(); } diff --git a/phpBB/phpbb/install/module_base.php b/phpBB/phpbb/install/module_base.php index 4464a89716..85ac4506c7 100644 --- a/phpBB/phpbb/install/module_base.php +++ b/phpBB/phpbb/install/module_base.php @@ -106,6 +106,7 @@ abstract class module_base implements module_interface { // Recover install progress $task_index = $this->recover_progress(); + /** @psalm-suppress InvalidTemplateParam */ $iterator = $this->task_collection->getIterator(); if ($task_index < $iterator->count()) From 733f4e2530f6248702e2ab33ce3548701244209f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:42:49 +0100 Subject: [PATCH 08/42] [ticket/16955] Wrap RecursiveDirectoryIteratorr calls for dot prefix filter PHPBB3-16955 --- .../recursive_dot_prefix_filter_iterator.php | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/iterator/recursive_dot_prefix_filter_iterator.php b/phpBB/phpbb/iterator/recursive_dot_prefix_filter_iterator.php index 4549e03e8e..08f5bde262 100644 --- a/phpBB/phpbb/iterator/recursive_dot_prefix_filter_iterator.php +++ b/phpBB/phpbb/iterator/recursive_dot_prefix_filter_iterator.php @@ -22,9 +22,38 @@ namespace phpbb\iterator; */ class recursive_dot_prefix_filter_iterator extends \RecursiveFilterIterator { - public function accept() + /** + * Check whether the current element of the iterator is acceptable + * + * @return bool + */ + public function accept(): bool { $filename = $this->current()->getFilename(); return $filename[0] !== '.' || !$this->current()->isDir(); } + + /** + * Get sub path + * + * @return string + */ + public function getSubPath(): string + { + $directory_iterator = $this->getInnerIterator(); + assert($directory_iterator instanceof \RecursiveDirectoryIterator); + return $directory_iterator->getSubPath(); + } + + /** + * Get sub path and name + * + * @return string + */ + public function getSubPathname(): string + { + $directory_iterator = $this->getInnerIterator(); + assert($directory_iterator instanceof \RecursiveDirectoryIterator); + return $directory_iterator->getSubPathname(); + } } From 96911b7403cfee13971ebde911163a434bde21ef Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:49:18 +0100 Subject: [PATCH 09/42] [ticket/16955] Clean up variable names and docblocks in notifications PHPBB3-16955 --- phpBB/phpbb/notification/manager.php | 32 +++++++++-- phpBB/phpbb/notification/method/email.php | 4 +- .../notification/method/messenger_base.php | 2 +- .../notification/method/method_interface.php | 2 +- .../notification/type/admin_activate_user.php | 16 +++--- .../phpbb/notification/type/approve_post.php | 17 +++--- .../phpbb/notification/type/approve_topic.php | 15 ++--- phpBB/phpbb/notification/type/base.php | 4 +- phpBB/phpbb/notification/type/bookmark.php | 18 +++--- .../notification/type/disapprove_post.php | 6 +- .../notification/type/disapprove_topic.php | 6 +- phpBB/phpbb/notification/type/forum.php | 16 +++--- .../phpbb/notification/type/group_request.php | 18 +++--- .../type/group_request_approved.php | 18 +++--- phpBB/phpbb/notification/type/mention.php | 8 +-- phpBB/phpbb/notification/type/pm.php | 30 +++++----- phpBB/phpbb/notification/type/post.php | 57 ++++++++++--------- .../phpbb/notification/type/post_in_queue.php | 18 +++--- phpBB/phpbb/notification/type/quote.php | 10 ++-- phpBB/phpbb/notification/type/report_pm.php | 31 +++++----- .../notification/type/report_pm_closed.php | 14 ++--- phpBB/phpbb/notification/type/report_post.php | 16 +++--- .../notification/type/report_post_closed.php | 14 ++--- phpBB/phpbb/notification/type/topic.php | 47 ++++++++------- .../notification/type/topic_in_queue.php | 18 +++--- 25 files changed, 235 insertions(+), 202 deletions(-) diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index 1c44b03507..06a5c6a907 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -873,9 +873,9 @@ class manager /** * Helper to get the list of methods enabled by default * - * @return method\method_interface[] + * @return string[] Default method types */ - public function get_default_methods() + public function get_default_methods(): array { $default_methods = array(); @@ -894,13 +894,20 @@ class manager * Helper to get the notifications item type class and set it up * * @param string $notification_type_name - * @param array $data + * @param array $data + * * @return type\type_interface + * @throws \Exception When type name is not o notification type */ public function get_item_type_class($notification_type_name, $data = array()) { $item = $this->load_object($notification_type_name); + if (!$item instanceof type\type_interface) + { + throw new \Exception('Supplied type name returned invalid service: ' . $notification_type_name); + } + $item->set_initial_data($data); return $item; @@ -910,18 +917,30 @@ class manager * Helper to get the notifications method class and set it up * * @param string $method_name + * * @return method\method_interface + * @throws \Exception When object name is not o notification method */ public function get_method_class($method_name) { - return $this->load_object($method_name); + $object = $this->load_object($method_name); + + if (!$object instanceof method\method_interface) + { + throw new \Exception('Supplied method name returned invalid service: ' . $method_name); + } + + return $object; } /** * Helper to load objects (notification types/methods) * * @param string $object_name + * * @return method\method_interface|type\type_interface + * @psalm-suppress NullableReturnStatement Invalid service will result in exception + * @throws \Exception When object name is not o notification method or type */ protected function load_object($object_name) { @@ -932,6 +951,11 @@ class manager $object->set_notification_manager($this); } + if (!$object instanceof method\method_interface && !$object instanceof type\type_interface) + { + throw new \Exception('Supplied object name returned invalid service: ' . $object_name); + } + return $object; } diff --git a/phpBB/phpbb/notification/method/email.php b/phpBB/phpbb/notification/method/email.php index 6892d0a7c6..ce81c58185 100644 --- a/phpBB/phpbb/notification/method/email.php +++ b/phpBB/phpbb/notification/method/email.php @@ -126,7 +126,7 @@ class email extends \phpbb\notification\method\messenger_base public function mark_notifications($notification_type_id, $item_id, $user_id, $time = false, $mark_read = true) { $sql = 'DELETE FROM ' . $this->notification_emails_table . ' - WHERE ' . ($notification_type_id !== false ? $this->db->sql_in_set('notification_type_id', $notification_type_id) : '1=1') . + WHERE ' . ($notification_type_id !== false ? $this->db->sql_in_set('notification_type_id', is_array($notification_type_id) ? $notification_type_id : [$notification_type_id]) : '1=1') . ($user_id !== false ? ' AND ' . $this->db->sql_in_set('user_id', $user_id) : '') . ($item_id !== false ? ' AND ' . $this->db->sql_in_set('item_id', $item_id) : ''); $this->db->sql_query($sql); @@ -138,7 +138,7 @@ class email extends \phpbb\notification\method\messenger_base public function mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time = false, $mark_read = true) { $sql = 'DELETE FROM ' . $this->notification_emails_table . ' - WHERE ' . ($notification_type_id !== false ? $this->db->sql_in_set('notification_type_id', $notification_type_id) : '1=1') . + WHERE ' . ($notification_type_id !== false ? $this->db->sql_in_set('notification_type_id', is_array($notification_type_id) ? $notification_type_id : [$notification_type_id]) : '1=1') . ($user_id !== false ? ' AND ' . $this->db->sql_in_set('user_id', $user_id) : '') . ($item_parent_id !== false ? ' AND ' . $this->db->sql_in_set('item_parent_id', $item_parent_id, false, true) : ''); $this->db->sql_query($sql); diff --git a/phpBB/phpbb/notification/method/messenger_base.php b/phpBB/phpbb/notification/method/messenger_base.php index c0b1b5d596..85461b282d 100644 --- a/phpBB/phpbb/notification/method/messenger_base.php +++ b/phpBB/phpbb/notification/method/messenger_base.php @@ -63,7 +63,7 @@ abstract class messenger_base extends \phpbb\notification\method\base * @param int $notify_method Notify method for messenger (e.g. NOTIFY_IM) * @param string $template_dir_prefix Base directory to prepend to the email template name * - * @return null + * @return void */ protected function notify_using_messenger($notify_method, $template_dir_prefix = '') { diff --git a/phpBB/phpbb/notification/method/method_interface.php b/phpBB/phpbb/notification/method/method_interface.php index aa13bfde69..2bade743ed 100644 --- a/phpBB/phpbb/notification/method/method_interface.php +++ b/phpBB/phpbb/notification/method/method_interface.php @@ -102,7 +102,7 @@ interface method_interface /** * Mark notifications read or unread from a parent identifier * - * @param string $notification_type_id Type identifier of item types + * @param string|int|array $notification_type_id Type identifier of item types * @param bool|int|array $item_parent_id Item parent id or array of item parent ids. False to mark read for all item parent 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) diff --git a/phpBB/phpbb/notification/type/admin_activate_user.php b/phpBB/phpbb/notification/type/admin_activate_user.php index 4f3dddba3e..1d8d5717f4 100644 --- a/phpBB/phpbb/notification/type/admin_activate_user.php +++ b/phpBB/phpbb/notification/type/admin_activate_user.php @@ -68,15 +68,15 @@ class admin_activate_user extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public static function get_item_id($user) + public static function get_item_id($type_data) { - return (int) $user['user_id']; + return (int) $type_data['user_id']; } /** * {@inheritdoc} */ - public static function get_item_parent_id($post) + public static function get_item_parent_id($type_data) { return 0; } @@ -84,7 +84,7 @@ class admin_activate_user extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public function find_users_for_notification($user, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), @@ -175,11 +175,11 @@ class admin_activate_user extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public function create_insert_array($user, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - $this->set_data('user_actkey', $user['user_actkey']); - $this->notification_time = $user['user_regdate']; + $this->set_data('user_actkey', $type_data['user_actkey']); + $this->notification_time = $type_data['user_regdate']; - parent::create_insert_array($user, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/approve_post.php b/phpBB/phpbb/notification/type/approve_post.php index e07a5256fe..98b04cc7cc 100644 --- a/phpBB/phpbb/notification/type/approve_post.php +++ b/phpBB/phpbb/notification/type/approve_post.php @@ -67,18 +67,18 @@ class approve_post extends \phpbb\notification\type\post /** * Find the users who want to receive notifications * - * @param array $post Data from submit_post + * @param array $type_data Data from submit_post * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - return $this->get_authorised_recipients(array($post['poster_id']), $post['forum_id'], array_merge($options, array( + return $this->get_authorised_recipients(array($type_data['poster_id']), $type_data['forum_id'], array_merge($options, array( 'item_type' => static::$notification_option['id'], ))); } @@ -89,12 +89,13 @@ class approve_post extends \phpbb\notification\type\post * and load data, before create_insert_array() is run. The data * returned from this function will be sent to create_insert_array(). * - * @param array $post Post data from submit_post + * @param array $type_data Post data from submit_post * @param array $notify_users Notify users list * Formatted from find_users_for_notification() + * * @return array Whatever you want to send to create_insert_array(). */ - public function pre_create_insert_array($post, $notify_users) + public function pre_create_insert_array($type_data, $notify_users) { // In the parent class, this is used to check if the post is already // read by a user and marks the notification read if it was marked read. @@ -106,11 +107,11 @@ class approve_post extends \phpbb\notification\type\post /** * {@inheritdoc} */ - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - $this->set_data('post_subject', $post['post_subject']); + $this->set_data('post_subject', $type_data['post_subject']); - parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); $this->notification_time = time(); } diff --git a/phpBB/phpbb/notification/type/approve_topic.php b/phpBB/phpbb/notification/type/approve_topic.php index c5292fa066..d072ff330a 100644 --- a/phpBB/phpbb/notification/type/approve_topic.php +++ b/phpBB/phpbb/notification/type/approve_topic.php @@ -67,18 +67,18 @@ class approve_topic extends \phpbb\notification\type\topic /** * Find the users who want to receive notifications * - * @param array $post Data from submit_post + * @param array $type_data Data from submit_post * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - return $this->get_authorised_recipients(array($post['poster_id']), $post['forum_id'], array_merge($options, array( + return $this->get_authorised_recipients(array($type_data['poster_id']), $type_data['forum_id'], array_merge($options, array( 'item_type' => static::$notification_option['id'], ))); } @@ -89,12 +89,13 @@ class approve_topic extends \phpbb\notification\type\topic * and load data, before create_insert_array() is run. The data * returned from this function will be sent to create_insert_array(). * - * @param array $post Post data from submit_post + * @param array $type_data Post data from submit_post * @param array $notify_users Notify users list * Formatted from find_users_for_notification() + * * @return array Whatever you want to send to create_insert_array(). */ - public function pre_create_insert_array($post, $notify_users) + public function pre_create_insert_array($type_data, $notify_users) { // In the parent class, this is used to check if the post is already // read by a user and marks the notification read if it was marked read. @@ -106,10 +107,10 @@ class approve_topic extends \phpbb\notification\type\topic /** * {@inheritdoc} */ - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); $this->notification_time = time(); } diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index 46f3650898..7c77154fe7 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -162,12 +162,12 @@ abstract class base implements \phpbb\notification\type\type_interface /** * Get special data (only important for the classes that extend this) * - * @param string $name Name of the variable to get + * @param string|false $name Name of the variable to get, false if all data should be returned * @return mixed */ protected function get_data($name) { - return ($name === false) ? $this->data['notification_data'] : ((isset($this->data['notification_data'][$name])) ? $this->data['notification_data'][$name] : null); + return ($name === false) ? $this->data['notification_data'] : ($this->data['notification_data'][$name] ?? null); } /** diff --git a/phpBB/phpbb/notification/type/bookmark.php b/phpBB/phpbb/notification/type/bookmark.php index 1b03b5ed13..487e3a7543 100644 --- a/phpBB/phpbb/notification/type/bookmark.php +++ b/phpBB/phpbb/notification/type/bookmark.php @@ -53,18 +53,18 @@ class bookmark extends \phpbb\notification\type\post */ public function is_available() { - return $this->config['allow_bookmarks']; + return (bool) $this->config['allow_bookmarks']; } /** * Find the users who want to receive notifications * - * @param array $post Data from submit_post + * @param array $type_data Data from submit_post * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), @@ -74,8 +74,8 @@ class bookmark extends \phpbb\notification\type\post $sql = 'SELECT user_id FROM ' . BOOKMARKS_TABLE . ' - WHERE ' . $this->db->sql_in_set('topic_id', $post['topic_id']) . ' - AND user_id <> ' . (int) $post['poster_id']; + WHERE ' . $this->db->sql_in_set('topic_id', $type_data['topic_id']) . ' + AND user_id <> ' . (int) $type_data['poster_id']; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -83,7 +83,7 @@ class bookmark extends \phpbb\notification\type\post } $this->db->sql_freeresult($result); - $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true); + $notify_users = $this->get_authorised_recipients($users, $type_data['forum_id'], $options, true); if (empty($notify_users)) { @@ -92,7 +92,7 @@ class bookmark extends \phpbb\notification\type\post // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $notified_users = $this->notification_manager->get_notified_users($this->get_type(), array( - 'item_parent_id' => static::get_item_parent_id($post), + 'item_parent_id' => static::get_item_parent_id($type_data), 'read' => 0, )); @@ -102,11 +102,11 @@ class bookmark extends \phpbb\notification\type\post /** @var bookmark $notification */ $notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data); - $update_responders = $notification->add_responders($post); + $update_responders = $notification->add_responders($type_data); if (!empty($update_responders)) { $this->notification_manager->update_notification($notification, $update_responders, array( - 'item_parent_id' => self::get_item_parent_id($post), + 'item_parent_id' => self::get_item_parent_id($type_data), 'read' => 0, 'user_id' => $user, )); diff --git a/phpBB/phpbb/notification/type/disapprove_post.php b/phpBB/phpbb/notification/type/disapprove_post.php index 01a7bb16e8..a92a69cf03 100644 --- a/phpBB/phpbb/notification/type/disapprove_post.php +++ b/phpBB/phpbb/notification/type/disapprove_post.php @@ -127,11 +127,11 @@ class disapprove_post extends \phpbb\notification\type\approve_post /** * {@inheritdoc} */ - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - $this->set_data('disapprove_reason', $post['disapprove_reason']); + $this->set_data('disapprove_reason', $type_data['disapprove_reason']); - parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); $this->notification_time = time(); } diff --git a/phpBB/phpbb/notification/type/disapprove_topic.php b/phpBB/phpbb/notification/type/disapprove_topic.php index 2c60a75312..d5e9b64804 100644 --- a/phpBB/phpbb/notification/type/disapprove_topic.php +++ b/phpBB/phpbb/notification/type/disapprove_topic.php @@ -127,11 +127,11 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic /** * {@inheritdoc} */ - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - $this->set_data('disapprove_reason', $post['disapprove_reason']); + $this->set_data('disapprove_reason', $type_data['disapprove_reason']); - parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); $this->notification_time = time(); } diff --git a/phpBB/phpbb/notification/type/forum.php b/phpBB/phpbb/notification/type/forum.php index 056d78602d..2d196f013f 100644 --- a/phpBB/phpbb/notification/type/forum.php +++ b/phpBB/phpbb/notification/type/forum.php @@ -44,12 +44,12 @@ class forum extends \phpbb\notification\type\post /** * Find the users who want to receive notifications * - * @param array $post Data from submit_post + * @param array $type_data Data from submit_post * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($post, $options = []) + public function find_users_for_notification($type_data, $options = []) { $options = array_merge([ 'ignore_users' => [], @@ -59,9 +59,9 @@ class forum extends \phpbb\notification\type\post $sql = 'SELECT user_id FROM ' . FORUMS_WATCH_TABLE . ' - WHERE forum_id = ' . (int) $post['forum_id'] . ' + WHERE forum_id = ' . (int) $type_data['forum_id'] . ' AND notify_status = ' . NOTIFY_YES . ' - AND user_id <> ' . (int) $post['poster_id']; + AND user_id <> ' . (int) $type_data['poster_id']; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -69,7 +69,7 @@ class forum extends \phpbb\notification\type\post } $this->db->sql_freeresult($result); - $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true); + $notify_users = $this->get_authorised_recipients($users, $type_data['forum_id'], $options, true); if (empty($notify_users)) { @@ -79,7 +79,7 @@ class forum extends \phpbb\notification\type\post // Try to find the users who already have been notified about replies and have not read them // Just update their notifications $notified_users = $this->notification_manager->get_notified_users($this->get_type(), [ - 'item_parent_id' => static::get_item_parent_id($post), + 'item_parent_id' => static::get_item_parent_id($type_data), 'read' => 0, ]); @@ -89,11 +89,11 @@ class forum extends \phpbb\notification\type\post /** @var post $notification */ $notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data); - $update_responders = $notification->add_responders($post); + $update_responders = $notification->add_responders($type_data); if (!empty($update_responders)) { $this->notification_manager->update_notification($notification, $update_responders, [ - 'item_parent_id' => self::get_item_parent_id($post), + 'item_parent_id' => self::get_item_parent_id($type_data), 'read' => 0, 'user_id' => $user, ]); diff --git a/phpBB/phpbb/notification/type/group_request.php b/phpBB/phpbb/notification/type/group_request.php index 34462de2e2..5c07730353 100644 --- a/phpBB/phpbb/notification/type/group_request.php +++ b/phpBB/phpbb/notification/type/group_request.php @@ -58,24 +58,24 @@ class group_request extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public static function get_item_id($group) + public static function get_item_id($type_data) { - return (int) $group['user_id']; + return (int) $type_data['user_id']; } /** * {@inheritdoc} */ - public static function get_item_parent_id($group) + public static function get_item_parent_id($type_data) { // Group id is the parent - return (int) $group['group_id']; + return (int) $type_data['group_id']; } /** * {@inheritdoc} */ - public function find_users_for_notification($group, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), @@ -84,7 +84,7 @@ class group_request extends \phpbb\notification\type\base $sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . ' WHERE group_leader = 1 - AND group_id = ' . (int) $group['group_id']; + AND group_id = ' . (int) $type_data['group_id']; $result = $this->db->sql_query($sql); $user_ids = array(); @@ -160,10 +160,10 @@ class group_request extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public function create_insert_array($group, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - $this->set_data('group_name', $group['group_name']); + $this->set_data('group_name', $type_data['group_name']); - parent::create_insert_array($group, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/group_request_approved.php b/phpBB/phpbb/notification/type/group_request_approved.php index 14f222bc1f..d57ab59abf 100644 --- a/phpBB/phpbb/notification/type/group_request_approved.php +++ b/phpBB/phpbb/notification/type/group_request_approved.php @@ -34,15 +34,15 @@ class group_request_approved extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public static function get_item_id($group) + public static function get_item_id($type_data) { - return (int) $group['group_id']; + return (int) $type_data['group_id']; } /** * {@inheritdoc} */ - public static function get_item_parent_id($group) + public static function get_item_parent_id($type_data) { return 0; } @@ -50,13 +50,13 @@ class group_request_approved extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public function find_users_for_notification($group, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $users = array(); - $group['user_ids'] = (!is_array($group['user_ids'])) ? array($group['user_ids']) : $group['user_ids']; + $type_data['user_ids'] = (!is_array($type_data['user_ids'])) ? array($type_data['user_ids']) : $type_data['user_ids']; - foreach ($group['user_ids'] as $user_id) + foreach ($type_data['user_ids'] as $user_id) { $users[$user_id] = $this->notification_manager->get_default_methods(); } @@ -83,11 +83,11 @@ class group_request_approved extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public function create_insert_array($group, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - $this->set_data('group_name', $group['group_name']); + $this->set_data('group_name', $type_data['group_name']); - parent::create_insert_array($group, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); } /** diff --git a/phpBB/phpbb/notification/type/mention.php b/phpBB/phpbb/notification/type/mention.php index fad31b9912..d05742054a 100644 --- a/phpBB/phpbb/notification/type/mention.php +++ b/phpBB/phpbb/notification/type/mention.php @@ -59,24 +59,24 @@ class mention extends post /** * {@inheritDoc} */ - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $user_ids = $this->helper->get_mentioned_user_ids($post['post_text']); + $user_ids = $this->helper->get_mentioned_user_ids($type_data['post_text']); $user_ids = array_unique($user_ids); - $user_ids = array_diff($user_ids, [(int) $post['poster_id']]); + $user_ids = array_diff($user_ids, [(int) $type_data['poster_id']]); if (empty($user_ids)) { return array(); } - return $this->get_authorised_recipients($user_ids, $post['forum_id'], $options, true); + return $this->get_authorised_recipients($user_ids, $type_data['forum_id'], $options, true); } /** diff --git a/phpBB/phpbb/notification/type/pm.php b/phpBB/phpbb/notification/type/pm.php index d7b458dace..8dffbc1bf4 100644 --- a/phpBB/phpbb/notification/type/pm.php +++ b/phpBB/phpbb/notification/type/pm.php @@ -67,19 +67,19 @@ class pm extends \phpbb\notification\type\base /** * Get the id of the * - * @param array $pm The data from the private message + * @param array $type_data The data from the private message */ - public static function get_item_id($pm) + public static function get_item_id($type_data) { - return (int) $pm['msg_id']; + return (int) $type_data['msg_id']; } /** * Get the id of the parent * - * @param array $pm The data from the pm + * @param array $type_data The data from the pm */ - public static function get_item_parent_id($pm) + public static function get_item_parent_id($type_data) { // No parent return 0; @@ -88,27 +88,27 @@ class pm extends \phpbb\notification\type\base /** * Find the users who want to receive notifications * - * @param array $pm Data from submit_pm + * @param array $type_data Data from submit_pm * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($pm, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - if (!count($pm['recipients'])) + if (!count($type_data['recipients'])) { return array(); } - unset($pm['recipients'][$pm['from_user_id']]); + unset($type_data['recipients'][$type_data['from_user_id']]); - $this->user_loader->load_users(array_keys($pm['recipients'])); + $this->user_loader->load_users(array_keys($type_data['recipients'])); - return $this->check_user_notification_options(array_keys($pm['recipients']), $options); + return $this->check_user_notification_options(array_keys($type_data['recipients']), $options); } /** @@ -194,12 +194,12 @@ class pm extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public function create_insert_array($pm, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - $this->set_data('from_user_id', $pm['from_user_id']); + $this->set_data('from_user_id', $type_data['from_user_id']); - $this->set_data('message_subject', $pm['message_subject']); + $this->set_data('message_subject', $type_data['message_subject']); - parent::create_insert_array($pm, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index db9ab3b9fe..022e184110 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -76,40 +76,42 @@ class post extends \phpbb\notification\type\base */ public function is_available() { - return $this->config['allow_topic_notify']; + return (bool) $this->config['allow_topic_notify']; } /** * Get the id of the item * - * @param array $post The data from the post + * @param array $type_data The data from the post + * * @return int The post id */ - public static function get_item_id($post) + public static function get_item_id($type_data) { - return (int) $post['post_id']; + return (int) $type_data['post_id']; } /** * Get the id of the parent * - * @param array $post The data from the post + * @param array $type_data The data from the post + * * @return int The topic id */ - public static function get_item_parent_id($post) + public static function get_item_parent_id($type_data) { - return (int) $post['topic_id']; + return (int) $type_data['topic_id']; } /** * Find the users who want to receive notifications * - * @param array $post Data from submit_post + * @param array $type_data Data from submit_post * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), @@ -119,9 +121,9 @@ class post extends \phpbb\notification\type\base $sql = 'SELECT user_id FROM ' . TOPICS_WATCH_TABLE . ' - WHERE topic_id = ' . (int) $post['topic_id'] . ' + WHERE topic_id = ' . (int) $type_data['topic_id'] . ' AND notify_status = ' . NOTIFY_YES . ' - AND user_id <> ' . (int) $post['poster_id']; + AND user_id <> ' . (int) $type_data['poster_id']; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -129,7 +131,7 @@ class post extends \phpbb\notification\type\base } $this->db->sql_freeresult($result); - $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true); + $notify_users = $this->get_authorised_recipients($users, $type_data['forum_id'], $options, true); if (empty($notify_users)) { @@ -138,7 +140,7 @@ class post extends \phpbb\notification\type\base // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $notified_users = $this->notification_manager->get_notified_users($this->get_type(), array( - 'item_parent_id' => static::get_item_parent_id($post), + 'item_parent_id' => static::get_item_parent_id($type_data), 'read' => 0, )); @@ -148,11 +150,11 @@ class post extends \phpbb\notification\type\base /** @var post $notification */ $notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data); - $update_responders = $notification->add_responders($post); + $update_responders = $notification->add_responders($type_data); if (!empty($update_responders)) { $this->notification_manager->update_notification($notification, $update_responders, array( - 'item_parent_id' => self::get_item_parent_id($post), + 'item_parent_id' => self::get_item_parent_id($type_data), 'read' => 0, 'user_id' => $user, )); @@ -338,12 +340,13 @@ class post extends \phpbb\notification\type\base * and load data, before create_insert_array() is run. The data * returned from this function will be sent to create_insert_array(). * - * @param array $post Post data from submit_post + * @param array $type_data Post data from submit_post * @param array $notify_users Notify users list * Formatted from find_users_for_notification() + * * @return array Whatever you want to send to create_insert_array(). */ - public function pre_create_insert_array($post, $notify_users) + public function pre_create_insert_array($type_data, $notify_users) { if (!count($notify_users) || !$this->inherit_read_status) { @@ -352,7 +355,7 @@ class post extends \phpbb\notification\type\base $tracking_data = array(); $sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . ' - WHERE topic_id = ' . (int) $post['topic_id'] . ' + WHERE topic_id = ' . (int) $type_data['topic_id'] . ' AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) @@ -367,21 +370,21 @@ class post extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - $this->set_data('poster_id', $post['poster_id']); + $this->set_data('poster_id', $type_data['poster_id']); - $this->set_data('topic_title', $post['topic_title']); + $this->set_data('topic_title', $type_data['topic_title']); - $this->set_data('post_subject', $post['post_subject']); + $this->set_data('post_subject', $type_data['post_subject']); - $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); + $this->set_data('post_username', (($type_data['poster_id'] == ANONYMOUS) ? $type_data['post_username'] : '')); - $this->set_data('forum_id', $post['forum_id']); + $this->set_data('forum_id', $type_data['forum_id']); - $this->set_data('forum_name', $post['forum_name']); + $this->set_data('forum_name', $type_data['forum_name']); - $this->notification_time = $post['post_time']; + $this->notification_time = $type_data['post_time']; // Topics can be "read" before they are public (while awaiting approval). // Make sure that if the user has read the topic, it's marked as read in the notification @@ -390,7 +393,7 @@ class post extends \phpbb\notification\type\base $this->notification_read = true; } - parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); } /** diff --git a/phpBB/phpbb/notification/type/post_in_queue.php b/phpBB/phpbb/notification/type/post_in_queue.php index eca5f5316d..a02dd9684e 100644 --- a/phpBB/phpbb/notification/type/post_in_queue.php +++ b/phpBB/phpbb/notification/type/post_in_queue.php @@ -69,19 +69,19 @@ class post_in_queue extends \phpbb\notification\type\post /** * Find the users who want to receive notifications * - * @param array $post Data from the post + * @param array $type_data Data from the post * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); // 0 is for global moderator permissions - $auth_approve = $this->auth->acl_get_list(false, $this->permission, array($post['forum_id'], 0)); + $auth_approve = $this->auth->acl_get_list(false, $this->permission, array($type_data['forum_id'], 0)); if (empty($auth_approve)) { @@ -90,9 +90,9 @@ class post_in_queue extends \phpbb\notification\type\post $has_permission = array(); - if (isset($auth_approve[$post['forum_id']][$this->permission])) + if (isset($auth_approve[$type_data['forum_id']][$this->permission])) { - $has_permission = $auth_approve[$post['forum_id']][$this->permission]; + $has_permission = $auth_approve[$type_data['forum_id']][$this->permission]; } if (isset($auth_approve[0][$this->permission])) @@ -101,13 +101,13 @@ class post_in_queue extends \phpbb\notification\type\post } sort($has_permission); - $auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $type_data['forum_id']); if (empty($auth_read)) { return array(); } - return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( + return $this->check_user_notification_options($auth_read[$type_data['forum_id']]['f_read'], array_merge($options, array( 'item_type' => static::$notification_option['id'], ))); } @@ -133,9 +133,9 @@ class post_in_queue extends \phpbb\notification\type\post /** * {@inheritdoc} */ - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); $this->notification_time = time(); } diff --git a/phpBB/phpbb/notification/type/quote.php b/phpBB/phpbb/notification/type/quote.php index 0f18c7b210..f8fd8e4d81 100644 --- a/phpBB/phpbb/notification/type/quote.php +++ b/phpBB/phpbb/notification/type/quote.php @@ -64,18 +64,18 @@ class quote extends \phpbb\notification\type\post /** * Find the users who want to receive notifications * - * @param array $post Data from submit_post + * @param array $type_data Data from submit_post * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $usernames = $this->utils->get_outermost_quote_authors($post['post_text']); + $usernames = $this->utils->get_outermost_quote_authors($type_data['post_text']); if (empty($usernames)) { @@ -91,7 +91,7 @@ class quote extends \phpbb\notification\type\post $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' WHERE ' . $this->db->sql_in_set('username_clean', $usernames) . ' - AND user_id <> ' . (int) $post['poster_id']; + AND user_id <> ' . (int) $type_data['poster_id']; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -99,7 +99,7 @@ class quote extends \phpbb\notification\type\post } $this->db->sql_freeresult($result); - return $this->get_authorised_recipients($users, $post['forum_id'], $options, true); + return $this->get_authorised_recipients($users, $type_data['forum_id'], $options, true); } /** diff --git a/phpBB/phpbb/notification/type/report_pm.php b/phpBB/phpbb/notification/type/report_pm.php index 6b92f12bec..c8a1ccae69 100644 --- a/phpBB/phpbb/notification/type/report_pm.php +++ b/phpBB/phpbb/notification/type/report_pm.php @@ -69,12 +69,13 @@ class report_pm extends \phpbb\notification\type\pm /** * Get the id of the parent * - * @param array $pm The data from the pm + * @param array $type_data The data from the pm + * * @return int The report id */ - public static function get_item_parent_id($pm) + public static function get_item_parent_id($type_data) { - return (int) $pm['report_id']; + return (int) $type_data['report_id']; } /** @@ -92,33 +93,33 @@ class report_pm extends \phpbb\notification\type\pm * Find the users who want to receive notifications * (copied from post_in_queue) * - * @param array $post Data from the post + * @param array $type_data Data from the post * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($post, $options = []) + public function find_users_for_notification($type_data, $options = []) { $options = array_merge([ 'ignore_users' => [], ], $options); // Global - $post['forum_id'] = 0; + $type_data['forum_id'] = 0; - $auth_approve = $this->auth->acl_get_list(false, $this->permission, $post['forum_id']); + $auth_approve = $this->auth->acl_get_list(false, $this->permission, $type_data['forum_id']); if (empty($auth_approve)) { return []; } - if (($key = array_search($this->user->data['user_id'], $auth_approve[$post['forum_id']][$this->permission]))) + if (($key = array_search($this->user->data['user_id'], $auth_approve[$type_data['forum_id']][$this->permission]))) { - unset($auth_approve[$post['forum_id']][$this->permission][$key]); + unset($auth_approve[$type_data['forum_id']][$this->permission][$key]); } - return $this->check_user_notification_options($auth_approve[$post['forum_id']][$this->permission], array_merge($options, [ + return $this->check_user_notification_options($auth_approve[$type_data['forum_id']][$this->permission], array_merge($options, [ 'item_type' => static::$notification_option['id'], ])); } @@ -246,13 +247,13 @@ class report_pm extends \phpbb\notification\type\pm /** * {@inheritdoc} */ - public function create_insert_array($post, $pre_create_data = []) + public function create_insert_array($type_data, $pre_create_data = []) { $this->set_data('reporter_id', $this->user->data['user_id']); - $this->set_data('reason_title', strtoupper($post['reason_title'])); - $this->set_data('reason_description', $post['reason_description']); - $this->set_data('report_text', $post['report_text']); + $this->set_data('reason_title', strtoupper($type_data['reason_title'])); + $this->set_data('reason_description', $type_data['reason_description']); + $this->set_data('report_text', $type_data['report_text']); - parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/report_pm_closed.php b/phpBB/phpbb/notification/type/report_pm_closed.php index 8afc48ebd9..083baeece8 100644 --- a/phpBB/phpbb/notification/type/report_pm_closed.php +++ b/phpBB/phpbb/notification/type/report_pm_closed.php @@ -64,23 +64,23 @@ class report_pm_closed extends \phpbb\notification\type\pm /** * Find the users who want to receive notifications * - * @param array $pm Data from submit_pm + * @param array $type_data Data from submit_pm * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($pm, $options = []) + public function find_users_for_notification($type_data, $options = []) { $options = array_merge([ 'ignore_users' => [], ], $options); - if ($pm['reporter'] == $this->user->data['user_id']) + if ($type_data['reporter'] == $this->user->data['user_id']) { return []; } - return $this->check_user_notification_options([$pm['reporter']], $options); + return $this->check_user_notification_options([$type_data['reporter']], $options); } /** @@ -161,11 +161,11 @@ class report_pm_closed extends \phpbb\notification\type\pm /** * {@inheritdoc} */ - public function create_insert_array($pm, $pre_create_data = []) + public function create_insert_array($type_data, $pre_create_data = []) { - $this->set_data('closer_id', $pm['closer_id']); + $this->set_data('closer_id', $type_data['closer_id']); - parent::create_insert_array($pm, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); $this->notification_time = time(); } diff --git a/phpBB/phpbb/notification/type/report_post.php b/phpBB/phpbb/notification/type/report_post.php index ac923cdeab..730a6a12f4 100644 --- a/phpBB/phpbb/notification/type/report_post.php +++ b/phpBB/phpbb/notification/type/report_post.php @@ -75,14 +75,14 @@ class report_post extends \phpbb\notification\type\post_in_queue /** * Find the users who want to receive notifications * - * @param array $post Data from the post + * @param array $type_data Data from the post * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { - $notify_users = parent::find_users_for_notification($post, $options); + $notify_users = parent::find_users_for_notification($type_data, $options); // never notify reporter unset($notify_users[$this->user->data['user_id']]); @@ -212,13 +212,13 @@ class report_post extends \phpbb\notification\type\post_in_queue /** * {@inheritdoc} */ - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { $this->set_data('reporter_id', $this->user->data['user_id']); - $this->set_data('reason_title', strtoupper($post['reason_title'])); - $this->set_data('reason_description', $post['reason_description']); - $this->set_data('report_text', $post['report_text']); + $this->set_data('reason_title', strtoupper($type_data['reason_title'])); + $this->set_data('reason_description', $type_data['reason_description']); + $this->set_data('report_text', $type_data['report_text']); - parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/report_post_closed.php b/phpBB/phpbb/notification/type/report_post_closed.php index d54ba44fbf..9e05e4c9cd 100644 --- a/phpBB/phpbb/notification/type/report_post_closed.php +++ b/phpBB/phpbb/notification/type/report_post_closed.php @@ -71,23 +71,23 @@ class report_post_closed extends \phpbb\notification\type\post /** * Find the users who want to receive notifications * - * @param array $post Data from submit_post + * @param array $type_data Data from submit_post * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($post, $options = []) + public function find_users_for_notification($type_data, $options = []) { $options = array_merge([ 'ignore_users' => [], ], $options); - if ($post['reporter'] == $this->user->data['user_id']) + if ($type_data['reporter'] == $this->user->data['user_id']) { return []; } - return $this->check_user_notification_options([$post['reporter']], $options); + return $this->check_user_notification_options([$type_data['reporter']], $options); } /** @@ -187,11 +187,11 @@ class report_post_closed extends \phpbb\notification\type\post /** * {@inheritdoc} */ - public function create_insert_array($post, $pre_create_data = []) + public function create_insert_array($type_data, $pre_create_data = []) { - $this->set_data('closer_id', $post['closer_id']); + $this->set_data('closer_id', $type_data['closer_id']); - parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); $this->notification_time = time(); } diff --git a/phpBB/phpbb/notification/type/topic.php b/phpBB/phpbb/notification/type/topic.php index 541bd4955a..715e0d47ed 100644 --- a/phpBB/phpbb/notification/type/topic.php +++ b/phpBB/phpbb/notification/type/topic.php @@ -76,40 +76,42 @@ class topic extends \phpbb\notification\type\base */ public function is_available() { - return $this->config['allow_forum_notify']; + return (bool) $this->config['allow_forum_notify']; } /** * Get the id of the item * - * @param array $post The data from the post + * @param array $type_data The data from the post + * * @return int The topic id */ - public static function get_item_id($post) + public static function get_item_id($type_data) { - return (int) $post['topic_id']; + return (int) $type_data['topic_id']; } /** * Get the id of the parent * - * @param array $post The data from the post + * @param array $type_data The data from the post + * * @return int The forum id */ - public static function get_item_parent_id($post) + public static function get_item_parent_id($type_data) { - return (int) $post['forum_id']; + return (int) $type_data['forum_id']; } /** * Find the users who want to receive notifications * - * @param array $topic Data from the topic + * @param array $type_data Data from the topic * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($topic, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), @@ -119,9 +121,9 @@ class topic extends \phpbb\notification\type\base $sql = 'SELECT user_id FROM ' . FORUMS_WATCH_TABLE . ' - WHERE forum_id = ' . (int) $topic['forum_id'] . ' + WHERE forum_id = ' . (int) $type_data['forum_id'] . ' AND notify_status = ' . NOTIFY_YES . ' - AND user_id <> ' . (int) $topic['poster_id']; + AND user_id <> ' . (int) $type_data['poster_id']; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -129,7 +131,7 @@ class topic extends \phpbb\notification\type\base } $this->db->sql_freeresult($result); - return $this->get_authorised_recipients($users, $topic['forum_id'], $options); + return $this->get_authorised_recipients($users, $type_data['forum_id'], $options); } /** @@ -254,12 +256,13 @@ class topic extends \phpbb\notification\type\base * and load data, before create_insert_array() is run. The data * returned from this function will be sent to create_insert_array(). * - * @param array $post Post data from submit_post + * @param array $type_data Post data from submit_post * @param array $notify_users Notify users list * Formatted from find_users_for_notification() + * * @return array Whatever you want to send to create_insert_array(). */ - public function pre_create_insert_array($post, $notify_users) + public function pre_create_insert_array($type_data, $notify_users) { if (!count($notify_users) || !$this->inherit_read_status) { @@ -268,7 +271,7 @@ class topic extends \phpbb\notification\type\base $tracking_data = array(); $sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . ' - WHERE topic_id = ' . (int) $post['topic_id'] . ' + WHERE topic_id = ' . (int) $type_data['topic_id'] . ' AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) @@ -283,17 +286,17 @@ class topic extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - $this->set_data('poster_id', $post['poster_id']); + $this->set_data('poster_id', $type_data['poster_id']); - $this->set_data('topic_title', $post['topic_title']); + $this->set_data('topic_title', $type_data['topic_title']); - $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); + $this->set_data('post_username', (($type_data['poster_id'] == ANONYMOUS) ? $type_data['post_username'] : '')); - $this->set_data('forum_name', $post['forum_name']); + $this->set_data('forum_name', $type_data['forum_name']); - $this->notification_time = $post['post_time']; + $this->notification_time = $type_data['post_time']; // Topics can be "read" before they are public (while awaiting approval). // Make sure that if the user has read the topic, it's marked as read in the notification @@ -302,6 +305,6 @@ class topic extends \phpbb\notification\type\base $this->notification_read = true; } - parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/topic_in_queue.php b/phpBB/phpbb/notification/type/topic_in_queue.php index 54dc50bcf2..523b8eb5a3 100644 --- a/phpBB/phpbb/notification/type/topic_in_queue.php +++ b/phpBB/phpbb/notification/type/topic_in_queue.php @@ -69,19 +69,19 @@ class topic_in_queue extends \phpbb\notification\type\topic /** * Find the users who want to receive notifications * - * @param array $topic Data from the topic + * @param array $type_data Data from the topic * @param array $options Options for finding users for notification * * @return array */ - public function find_users_for_notification($topic, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); // 0 is for global moderator permissions - $auth_approve = $this->auth->acl_get_list(false, 'm_approve', array($topic['forum_id'], 0)); + $auth_approve = $this->auth->acl_get_list(false, 'm_approve', array($type_data['forum_id'], 0)); if (empty($auth_approve)) { @@ -90,9 +90,9 @@ class topic_in_queue extends \phpbb\notification\type\topic $has_permission = array(); - if (isset($auth_approve[$topic['forum_id']][$this->permission])) + if (isset($auth_approve[$type_data['forum_id']][$this->permission])) { - $has_permission = $auth_approve[$topic['forum_id']][$this->permission]; + $has_permission = $auth_approve[$type_data['forum_id']][$this->permission]; } if (isset($auth_approve[0][$this->permission])) @@ -101,13 +101,13 @@ class topic_in_queue extends \phpbb\notification\type\topic } sort($has_permission); - $auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $topic['forum_id']); + $auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $type_data['forum_id']); if (empty($auth_read)) { return array(); } - return $this->check_user_notification_options($auth_read[$topic['forum_id']]['f_read'], array_merge($options, array( + return $this->check_user_notification_options($auth_read[$type_data['forum_id']]['f_read'], array_merge($options, array( 'item_type' => static::$notification_option['id'], ))); } @@ -125,9 +125,9 @@ class topic_in_queue extends \phpbb\notification\type\topic /** * {@inheritdoc} */ - public function create_insert_array($topic, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - parent::create_insert_array($topic, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); $this->notification_time = time(); } From 5b23dcd6060b755b5ca4636606dd4e0b384e7be2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:50:57 +0100 Subject: [PATCH 10/42] [ticket/16955] Fix another batch of docblocks PHPBB3-16955 --- phpBB/phpbb/language/language.php | 14 +++++--------- phpBB/phpbb/lock/flock.php | 4 ++-- phpBB/phpbb/log/log.php | 9 ++++++++- phpBB/phpbb/mention/source/base_user.php | 4 ++-- phpBB/phpbb/mention/source/group.php | 2 +- phpBB/phpbb/mention/source/team.php | 2 +- phpBB/phpbb/message/message.php | 2 +- phpBB/phpbb/mimetype/content_guesser.php | 2 +- phpBB/phpbb/mimetype/extension_guesser.php | 10 +--------- phpBB/phpbb/mimetype/guesser.php | 6 +++--- phpBB/phpbb/mimetype/guesser_interface.php | 2 +- phpBB/phpbb/pagination.php | 7 ++++--- .../passwords/driver/driver_interface.php | 2 +- phpBB/phpbb/passwords/helper.php | 6 ++++-- phpBB/phpbb/passwords/manager.php | 6 +++--- phpBB/phpbb/php/ini.php | 19 +++++++++++-------- phpBB/phpbb/plupload/plupload.php | 8 ++++---- phpBB/phpbb/profilefields/lang_helper.php | 2 +- phpBB/phpbb/profilefields/type/type_base.php | 6 +++--- phpBB/phpbb/profilefields/type/type_bool.php | 15 +++++++++------ .../profilefields/type/type_dropdown.php | 15 +++++++++------ .../profilefields/type/type_interface.php | 2 +- phpBB/phpbb/report/controller/report.php | 8 ++++++-- phpBB/phpbb/report/handler_factory.php | 13 ++++++++++--- phpBB/phpbb/report/report_handler.php | 2 +- 25 files changed, 93 insertions(+), 75 deletions(-) diff --git a/phpBB/phpbb/language/language.php b/phpBB/phpbb/language/language.php index bf82b26b03..6c59e02bba 100644 --- a/phpBB/phpbb/language/language.php +++ b/phpBB/phpbb/language/language.php @@ -298,7 +298,7 @@ class language if ($lang === $key) { - return $key; + return (string) $key; } // If the language entry is a string, we simply mimic sprintf() behaviour @@ -315,7 +315,7 @@ class language else if (count($lang) == 0) { // If the language entry is an empty array, we just return the language key - return $key; + return (string) $key; } // It is an array... now handle different nullar/singular/plural forms @@ -406,13 +406,6 @@ class language $number = (int) $number; $plural_rule = ($force_rule !== false) ? $force_rule : ((isset($this->lang['PLURAL_RULE'])) ? $this->lang['PLURAL_RULE'] : 1); - if ($plural_rule > 15 || $plural_rule < 0) - { - throw new invalid_plural_rule_exception('INVALID_PLURAL_RULE', array( - 'plural_rule' => $plural_rule, - )); - } - /** * The following plural rules are based on a list published by the Mozilla Developer Network * https://developer.mozilla.org/en/Localization_and_Plurals @@ -565,6 +558,9 @@ class language * 2 - everything else: 0, 2, 3, ... 10, 11, 12, ... 20, 22, ... */ return (($number % 10 === 1) && ($number % 100 != 11)) ? 1 : 2; + + default: + throw new invalid_plural_rule_exception('INVALID_PLURAL_RULE', ['plural_rule' => $plural_rule]); } } diff --git a/phpBB/phpbb/lock/flock.php b/phpBB/phpbb/lock/flock.php index 42ec8da030..f3a59f0a86 100644 --- a/phpBB/phpbb/lock/flock.php +++ b/phpBB/phpbb/lock/flock.php @@ -27,7 +27,7 @@ class flock /** * File pointer for the lock file - * @var string|bool + * @var resource|closed-resource|false */ private $lock_fp; @@ -130,7 +130,7 @@ class flock * Note: Attempting to release a lock that is already released, * that is, calling release() multiple times, is harmless. * - * @return null + * @return void */ public function release() { diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index 3b8caf6832..385251eaab 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -764,7 +764,14 @@ class log implements \phpbb\log\log_interface } $log[$key]['reportee_username'] = $reportee_data_list[$row['reportee_id']]['username']; - $log[$key]['reportee_username_full'] = get_username_string('full', $row['reportee_id'], $reportee_data_list[$row['reportee_id']]['username'], $reportee_data_list[$row['reportee_id']]['user_colour'], false, $profile_url); + $log[$key]['reportee_username_full'] = get_username_string( + 'full', + $row['reportee_id'], + $reportee_data_list[$row['reportee_id']]['username'], + $reportee_data_list[$row['reportee_id']]['user_colour'], + false, + $profile_url + ); } } diff --git a/phpBB/phpbb/mention/source/base_user.php b/phpBB/phpbb/mention/source/base_user.php index 7e9b41d67d..340abf6848 100644 --- a/phpBB/phpbb/mention/source/base_user.php +++ b/phpBB/phpbb/mention/source/base_user.php @@ -34,8 +34,8 @@ abstract class base_user implements source_interface /** @var string */ protected $php_ext; - /** @var string|false */ - protected $cache_ttl = false; + /** @var int */ + protected $cache_ttl = 0; /** * base_user constructor. diff --git a/phpBB/phpbb/mention/source/group.php b/phpBB/phpbb/mention/source/group.php index 11a8e02e94..dd1ee97898 100644 --- a/phpBB/phpbb/mention/source/group.php +++ b/phpBB/phpbb/mention/source/group.php @@ -15,7 +15,7 @@ namespace phpbb\mention\source; class group extends base_group { - /** @var string|false */ + /** @var int */ protected $cache_ttl = 300; /** diff --git a/phpBB/phpbb/mention/source/team.php b/phpBB/phpbb/mention/source/team.php index 02fd8cefbb..5b8e339158 100644 --- a/phpBB/phpbb/mention/source/team.php +++ b/phpBB/phpbb/mention/source/team.php @@ -15,7 +15,7 @@ namespace phpbb\mention\source; class team extends base_user { - /** @var string|false */ + /** @var int */ protected $cache_ttl = 300; /** diff --git a/phpBB/phpbb/message/message.php b/phpBB/phpbb/message/message.php index 1077d23513..53821d5412 100644 --- a/phpBB/phpbb/message/message.php +++ b/phpBB/phpbb/message/message.php @@ -234,7 +234,7 @@ class message * * @param \messenger $messenger * @param string $contact - * @return null + * @return void */ public function send(\messenger $messenger, $contact) { diff --git a/phpBB/phpbb/mimetype/content_guesser.php b/phpBB/phpbb/mimetype/content_guesser.php index f3ad7f5f41..08d3f19ebf 100644 --- a/phpBB/phpbb/mimetype/content_guesser.php +++ b/phpBB/phpbb/mimetype/content_guesser.php @@ -28,6 +28,6 @@ class content_guesser extends guesser_base */ public function guess($file, $file_name = '') { - return mime_content_type($file); + return mime_content_type($file) ?: null; } } diff --git a/phpBB/phpbb/mimetype/extension_guesser.php b/phpBB/phpbb/mimetype/extension_guesser.php index bb674c024a..44ecfbde7d 100644 --- a/phpBB/phpbb/mimetype/extension_guesser.php +++ b/phpBB/phpbb/mimetype/extension_guesser.php @@ -425,7 +425,6 @@ class extension_guesser extends guesser_base 'wb1' => 'application/x-qpro', 'wbmp' => 'image/vnd.wap.wbmp', 'web' => 'application/vnd.xara', - 'webm' => 'audio/webm', 'webm' => 'video/webm', 'wiz' => 'application/msword', 'wk1' => 'application/x-123', @@ -505,13 +504,6 @@ class extension_guesser extends guesser_base { $extension = pathinfo($file_name, PATHINFO_EXTENSION); - if (isset($this->extension_map[$extension])) - { - return $this->extension_map[$extension]; - } - else - { - return null; - } + return $this->extension_map[$extension] ?? null; } } diff --git a/phpBB/phpbb/mimetype/guesser.php b/phpBB/phpbb/mimetype/guesser.php index 9b2c184eeb..16084c9a86 100644 --- a/phpBB/phpbb/mimetype/guesser.php +++ b/phpBB/phpbb/mimetype/guesser.php @@ -102,7 +102,7 @@ class guesser * @param string $file Path to file * @param string $file_name The real file name * - * @return string Guess for mimetype of file + * @return string|false Guess for mimetype of file or false if file can't be opened */ public function guess($file, $file_name = '') { @@ -140,13 +140,13 @@ class guesser * will always overwrite the default application/octet-stream. * * @param string $mime_type The current mime type - * @param string $guess The current mime type guess + * @param string|null|false $guess The current mime type guess * * @return string The best mime type based on current mime type and guess */ public function choose_mime_type($mime_type, $guess) { - if ($guess === null || $guess == 'application/octet-stream') + if ($guess === false || $guess === null || $guess == 'application/octet-stream') { return $mime_type; } diff --git a/phpBB/phpbb/mimetype/guesser_interface.php b/phpBB/phpbb/mimetype/guesser_interface.php index a93e85c7f0..a2dff66617 100644 --- a/phpBB/phpbb/mimetype/guesser_interface.php +++ b/phpBB/phpbb/mimetype/guesser_interface.php @@ -28,7 +28,7 @@ interface guesser_interface * @param string $file Path to file * @param string $file_name The real file name * - * @return string Guess for mimetype of file + * @return string|null Guess for mimetype of file */ public function guess($file, $file_name = ''); diff --git a/phpBB/phpbb/pagination.php b/phpBB/phpbb/pagination.php index a7086f6691..e07c2988c1 100644 --- a/phpBB/phpbb/pagination.php +++ b/phpBB/phpbb/pagination.php @@ -285,11 +285,12 @@ class pagination * * @param int $per_page the number of items, posts, etc. per page * @param int $start the item which should be considered currently active, used to determine the page we're on + * * @return int Current page number */ - public function get_on_page($per_page, $start) + public function get_on_page(int $per_page, int $start): int { - return floor((int) $start / (int) $per_page) + 1; + return (int) floor($start / $per_page) + 1; } /** @@ -318,7 +319,7 @@ class pagination { if ($start < 0 || $start >= $num_items) { - return ($start < 0 || $num_items <= 0) ? 0 : floor(($num_items - 1) / $per_page) * $per_page; + return ($start < 0 || $num_items <= 0) ? 0 : (int) floor(($num_items - 1) / $per_page) * $per_page; } return $start; diff --git a/phpBB/phpbb/passwords/driver/driver_interface.php b/phpBB/phpbb/passwords/driver/driver_interface.php index 3974484f13..a50fd02eb6 100644 --- a/phpBB/phpbb/passwords/driver/driver_interface.php +++ b/phpBB/phpbb/passwords/driver/driver_interface.php @@ -63,7 +63,7 @@ interface driver_interface * @param string $hash Password hash * @param bool $full Return full settings or only settings * related to the salt - * @return string String containing the hash settings + * @return string|false String containing the hash settings or false if settings are empty or not supported */ public function get_settings_only($hash, $full = false); } diff --git a/phpBB/phpbb/passwords/helper.php b/phpBB/phpbb/passwords/helper.php index c2a49202cd..8c9e7ca555 100644 --- a/phpBB/phpbb/passwords/helper.php +++ b/phpBB/phpbb/passwords/helper.php @@ -50,8 +50,8 @@ class helper * @param string $type Data type of the supplied value * @param string $value Value that should be put into the data array * - * @return string|null Return complete combined hash if type is neither - * 'prefix' nor 'settings', nothing if it is + * @return string|false Return complete combined hash if type is neither + * 'prefix' nor 'settings', false if it is */ public function combine_hash_output(&$data, $type, $value) { @@ -70,6 +70,8 @@ class helper // Return full hash return $data['prefix'] . $data['settings'] . '$' . $value; } + + return false; } /** diff --git a/phpBB/phpbb/passwords/manager.php b/phpBB/phpbb/passwords/manager.php index 574e381d85..33d7196d22 100644 --- a/phpBB/phpbb/passwords/manager.php +++ b/phpBB/phpbb/passwords/manager.php @@ -115,7 +115,7 @@ class manager /** * Fill algorithm type map * - * @param \phpbb\di\service_collection $hashing_algorithms + * @param \phpbb\di\service_collection|array $hashing_algorithms */ protected function fill_type_map($hashing_algorithms) { @@ -154,7 +154,7 @@ class manager * * @param string $hash Password hash that should be checked * - * @return object|bool The hash type object or false if the specified + * @return array|bool|object The hash type object or false if the specified * type is not supported */ public function detect_algorithm($hash) @@ -276,7 +276,7 @@ class manager // First find out what kind of hash we're dealing with $stored_hash_type = $this->detect_algorithm($hash); - if ($stored_hash_type == false) + if (!$stored_hash_type) { // Still check MD5 hashes as that is what the installer // will default to for the admin user diff --git a/phpBB/phpbb/php/ini.php b/phpBB/phpbb/php/ini.php index 24a5b5ecec..441e3ff7f6 100644 --- a/phpBB/phpbb/php/ini.php +++ b/phpBB/phpbb/php/ini.php @@ -137,15 +137,18 @@ class ini // Already in bytes. return phpbb_to_numeric($value); } - else if (strlen($value) < 2) + else if (is_string($value)) { - // Single character. - return false; - } - else if (strlen($value) < 3 && $value[0] === '-') - { - // Two characters but the first one is a minus. - return false; + if (strlen($value) < 2) + { + // Single character. + return false; + } + else if (strlen($value) < 3 && $value[0] === '-') + { + // Two characters but the first one is a minus. + return false; + } } $value_lower = strtolower($value); diff --git a/phpBB/phpbb/plupload/plupload.php b/phpBB/phpbb/plupload/plupload.php index ea8cfef5d0..ed749fdbe0 100644 --- a/phpBB/phpbb/plupload/plupload.php +++ b/phpBB/phpbb/plupload/plupload.php @@ -29,7 +29,7 @@ class plupload protected $config; /** - * @var \phpbb\request\request_interface + * @var \phpbb\request\request */ protected $request; @@ -65,12 +65,12 @@ class plupload * * @param string $phpbb_root_path * @param \phpbb\config\config $config - * @param \phpbb\request\request_interface $request + * @param \phpbb\request\request $request * @param \phpbb\user $user * @param \bantu\IniGetWrapper\IniGetWrapper $php_ini * @param \phpbb\mimetype\guesser $mimetype_guesser */ - public function __construct($phpbb_root_path, \phpbb\config\config $config, \phpbb\request\request_interface $request, \phpbb\user $user, \bantu\IniGetWrapper\IniGetWrapper $php_ini, \phpbb\mimetype\guesser $mimetype_guesser) + public function __construct($phpbb_root_path, \phpbb\config\config $config, \phpbb\request\request $request, \phpbb\user $user, \bantu\IniGetWrapper\IniGetWrapper $php_ini, \phpbb\mimetype\guesser $mimetype_guesser) { $this->phpbb_root_path = $phpbb_root_path; $this->config = $config; @@ -308,7 +308,7 @@ class plupload } } - return floor($max / 2); + return (int) floor($max / 2); } protected function temporary_filepath($file_name) diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 2e353722b2..499a01b7f0 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -126,7 +126,7 @@ class lang_helper * @param int $field_id Database ID of the field * @param int $lang_id ID of the language * @param int $field_value Selected value of the field - * @return string + * @return string|array */ public function get($field_id, $lang_id, $field_value = null) { diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 9b4bada26d..8fe4b38c46 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -183,8 +183,7 @@ abstract class type_base implements type_interface } /** - * Return templated value/field. Possible values for $mode are: - * change == user is able to set/enter profile values; preview == just show the value + * {@inheritDoc} */ public function process_field_row($mode, $profile_row) { @@ -201,6 +200,7 @@ abstract class type_base implements type_interface // Assign template variables $this->generate_field($profile_row, $preview_options); - return $this->template->assign_display('cp_body'); + $compiled_template = $this->template->assign_display('cp_body'); + return is_string($compiled_template) ? $compiled_template : ''; } } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 9c09e27bc4..c795eb27e5 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -232,13 +232,16 @@ class type_bool extends type_base } $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); - foreach ($options as $option_id => $option_value) + if (is_array($options)) { - $this->template->assign_block_vars('bool.options', array( - 'OPTION_ID' => $option_id, - 'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '', - 'VALUE' => $option_value, - )); + foreach ($options as $option_id => $option_value) + { + $this->template->assign_block_vars('bool.options', array( + 'OPTION_ID' => $option_id, + 'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '', + 'VALUE' => $option_value, + )); + } } } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index a32de40558..99f8906e76 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -233,13 +233,16 @@ class type_dropdown extends type_base $this->template->assign_block_vars('dropdown', array_change_key_case($profile_row, CASE_UPPER)); $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); - foreach ($options as $option_id => $option_value) + if (is_array($options)) { - $this->template->assign_block_vars('dropdown.options', array( - 'OPTION_ID' => $option_id, - 'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '', - 'VALUE' => $option_value, - )); + foreach ($options as $option_id => $option_value) + { + $this->template->assign_block_vars('dropdown.options', array( + 'OPTION_ID' => $option_id, + 'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '', + 'VALUE' => $option_value, + )); + } } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 93b9e4b893..abde7f853a 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -220,7 +220,7 @@ interface type_interface * * @param string $mode Mode for displaying the field (preview|change) * @param array $profile_row Array with data for this field - * @return null + * @return string */ public function process_field_row($mode, $profile_row); } diff --git a/phpBB/phpbb/report/controller/report.php b/phpBB/phpbb/report/controller/report.php index e151d0d291..026f450d85 100644 --- a/phpBB/phpbb/report/controller/report.php +++ b/phpBB/phpbb/report/controller/report.php @@ -14,6 +14,7 @@ namespace phpbb\report\controller; use phpbb\exception\http_exception; +use phpbb\report\report_handler_interface; use Symfony\Component\HttpFoundation\RedirectResponse; class report @@ -61,6 +62,9 @@ class report /** * @var \phpbb\report\handler_factory */ + protected $report_factory; + + /** @var report_handler_interface */ protected $report_handler; /** @@ -78,7 +82,7 @@ class report $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; $this->captcha_factory = $captcha_factory; - $this->report_handler = $report_factory; + $this->report_factory = $report_factory; // User interface factory $this->report_reason_provider = $ui_provider; @@ -97,7 +101,7 @@ class report public function handle($id, $mode) { // Get report handler - $this->report_handler = $this->report_handler->get_instance($mode); + $this->report_handler = $this->report_factory->get_instance($mode); $this->user->add_lang('mcp'); diff --git a/phpBB/phpbb/report/handler_factory.php b/phpBB/phpbb/report/handler_factory.php index b25386c4b2..bc371d5944 100644 --- a/phpBB/phpbb/report/handler_factory.php +++ b/phpBB/phpbb/report/handler_factory.php @@ -36,21 +36,28 @@ class handler_factory * Return a new instance of an appropriate report handler * * @param string $type - * @return \phpbb\report\report_handler_interface + * @return report_handler_interface * @throws factory_invalid_argument_exception if $type is not valid */ public function get_instance($type) { + $report_handler = null; switch ($type) { case 'pm': - return $this->container->get('phpbb.report.handlers.report_handler_pm'); + $report_handler = $this->container->get('phpbb.report.handlers.report_handler_pm'); break; + case 'post': - return $this->container->get('phpbb.report.handlers.report_handler_post'); + $report_handler = $this->container->get('phpbb.report.handlers.report_handler_post'); break; } + if ($report_handler instanceof report_handler_interface) + { + return $report_handler; + } + throw new factory_invalid_argument_exception(); } } diff --git a/phpBB/phpbb/report/report_handler.php b/phpBB/phpbb/report/report_handler.php index ec2f1e035f..6328ed1440 100644 --- a/phpBB/phpbb/report/report_handler.php +++ b/phpBB/phpbb/report/report_handler.php @@ -99,6 +99,6 @@ abstract class report_handler implements report_handler_interface $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); - return $this->db->sql_nextid(); + return (int) $this->db->sql_nextid(); } } From 056f7867693f5957503b9da13929671bc7ec5cee Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:52:27 +0100 Subject: [PATCH 11/42] [ticket/16955] Clean up request classes PHPBB3-16955 --- .../request/deactivated_super_global.php | 4 ++ phpBB/phpbb/request/request.php | 68 +++++++++---------- phpBB/phpbb/request/request_interface.php | 24 +++---- phpBB/phpbb/request/type_cast_helper.php | 2 +- phpBB/phpbb/routing/helper.php | 2 +- tests/mock/request.php | 2 +- 6 files changed, 53 insertions(+), 49 deletions(-) diff --git a/phpBB/phpbb/request/deactivated_super_global.php b/phpBB/phpbb/request/deactivated_super_global.php index 01e038e8be..ba7111e000 100644 --- a/phpBB/phpbb/request/deactivated_super_global.php +++ b/phpBB/phpbb/request/deactivated_super_global.php @@ -100,6 +100,8 @@ class deactivated_super_global implements \ArrayAccess, \Countable, \IteratorAgg /** * Part of the \Countable implementation, will always result in a FATAL error + * @return void + * @psalm-suppress InvalidReturnType */ public function count() { @@ -108,6 +110,8 @@ class deactivated_super_global implements \ArrayAccess, \Countable, \IteratorAgg /** * Part of the Traversable/IteratorAggregate implementation, will always result in a FATAL error + * @return void + * @psalm-suppress InvalidReturnType */ public function getIterator() { diff --git a/phpBB/phpbb/request/request.php b/phpBB/phpbb/request/request.php index e31be57d65..cf81dc42c6 100644 --- a/phpBB/phpbb/request/request.php +++ b/phpBB/phpbb/request/request.php @@ -19,18 +19,18 @@ namespace phpbb\request; * It provides a method to disable access to input data through super globals. * This should force MOD authors to read about data validation. */ -class request implements \phpbb\request\request_interface +class request implements request_interface { /** * @var array The names of super global variables that this class should protect if super globals are disabled. */ protected $super_globals = array( - \phpbb\request\request_interface::POST => '_POST', - \phpbb\request\request_interface::GET => '_GET', - \phpbb\request\request_interface::REQUEST => '_REQUEST', - \phpbb\request\request_interface::COOKIE => '_COOKIE', - \phpbb\request\request_interface::SERVER => '_SERVER', - \phpbb\request\request_interface::FILES => '_FILES', + request_interface::POST => '_POST', + request_interface::GET => '_GET', + request_interface::REQUEST => '_REQUEST', + request_interface::COOKIE => '_COOKIE', + request_interface::SERVER => '_SERVER', + request_interface::FILES => '_FILES', ); /** @@ -74,8 +74,8 @@ class request implements \phpbb\request\request_interface } // simulate request_order = GP - $this->original_request = $this->input[\phpbb\request\request_interface::REQUEST]; - $this->input[\phpbb\request\request_interface::REQUEST] = $this->input[\phpbb\request\request_interface::POST] + $this->input[\phpbb\request\request_interface::GET]; + $this->original_request = $this->input[request_interface::REQUEST]; + $this->input[request_interface::REQUEST] = $this->input[request_interface::POST] + $this->input[request_interface::GET]; if ($disable_super_globals) { @@ -140,10 +140,10 @@ class request implements \phpbb\request\request_interface * @param string $var_name The name of the variable that shall be overwritten * @param mixed $value The value which the variable shall contain. * If this is null the variable will be unset. - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * Specifies which super global shall be changed */ - public function overwrite($var_name, $value, $super_global = \phpbb\request\request_interface::REQUEST) + public function overwrite($var_name, $value, $super_global = request_interface::REQUEST) { if (!isset($this->super_globals[$super_global])) { @@ -181,13 +181,13 @@ class request implements \phpbb\request\request_interface * This function will always return a value of the same type as the default. * @param bool $multibyte If $default is a string this parameter has to be true if the variable may contain any UTF-8 characters * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * Specifies which super global should be used * * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the * the same as that of $default. If the variable is not set $default is returned. */ - public function variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST) + public function variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST) { return $this->_variable($var_name, $default, $multibyte, $super_global, true); } @@ -205,13 +205,13 @@ class request implements \phpbb\request\request_interface * This function will always return a value of the same type as the default. * @param bool $multibyte If $default is a string this parameter has to be true if the variable may contain any UTF-8 characters * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * Specifies which super global should be used * * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the * the same as that of $default. If the variable is not set $default is returned. */ - public function untrimmed_variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST) + public function untrimmed_variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST) { return $this->_variable($var_name, $default, $multibyte, $super_global, false); } @@ -219,7 +219,7 @@ class request implements \phpbb\request\request_interface /** * {@inheritdoc} */ - public function raw_variable($var_name, $default, $super_global = \phpbb\request\request_interface::REQUEST) + public function raw_variable($var_name, $default, $super_global = request_interface::REQUEST) { $path = false; @@ -276,9 +276,9 @@ class request implements \phpbb\request\request_interface { $multibyte = true; - if ($this->is_set($var_name, \phpbb\request\request_interface::SERVER)) + if ($this->is_set($var_name, request_interface::SERVER)) { - return $this->variable($var_name, $default, $multibyte, \phpbb\request\request_interface::SERVER); + return $this->variable($var_name, $default, $multibyte, request_interface::SERVER); } else { @@ -312,7 +312,7 @@ class request implements \phpbb\request\request_interface */ public function file($form_name) { - return $this->variable($form_name, array('name' => 'none'), true, \phpbb\request\request_interface::FILES); + return $this->variable($form_name, array('name' => 'none'), true, request_interface::FILES); } /** @@ -327,7 +327,7 @@ class request implements \phpbb\request\request_interface */ public function is_set_post($name) { - return $this->is_set($name, \phpbb\request\request_interface::POST); + return $this->is_set($name, request_interface::POST); } /** @@ -335,12 +335,12 @@ class request implements \phpbb\request\request_interface * arrays. * * @param string $var Name of the variable - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * Specifies the super global which shall be checked * * @return bool True if the variable was sent as input */ - public function is_set($var, $super_global = \phpbb\request\request_interface::REQUEST) + public function is_set($var, $super_global = request_interface::REQUEST) { return isset($this->input[$super_global][$var]); } @@ -370,13 +370,13 @@ class request implements \phpbb\request\request_interface /** * Returns all variable names for a given super global * - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * The super global from which names shall be taken * * @return array All variable names that are set for the super global. * Pay attention when using these, they are unsanitised! */ - public function variable_names($super_global = \phpbb\request\request_interface::REQUEST) + public function variable_names($super_global = request_interface::REQUEST) { if (!isset($this->input[$super_global])) { @@ -397,14 +397,14 @@ class request implements \phpbb\request\request_interface * This function will always return a value of the same type as the default. * @param bool $multibyte If $default is a string this parameter has to be true if the variable may contain any UTF-8 characters * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * Specifies which super global should be used * @param bool $trim Indicates whether trim() should be applied to string values. * * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the * the same as that of $default. If the variable is not set $default is returned. */ - protected function _variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST, $trim = true) + protected function _variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST, $trim = true) { $var = $this->raw_variable($var_name, $default, $super_global); @@ -424,7 +424,7 @@ class request implements \phpbb\request\request_interface /** * {@inheritdoc} */ - public function get_super_global($super_global = \phpbb\request\request_interface::REQUEST) + public function get_super_global($super_global = request_interface::REQUEST) { return $this->input[$super_global]; } @@ -432,23 +432,23 @@ class request implements \phpbb\request\request_interface /** * {@inheritdoc} */ - public function escape($var, $multibyte) + public function escape($value, $multibyte) { - if (is_array($var)) + if (is_array($value)) { $result = array(); - foreach ($var as $key => $value) + foreach ($value as $key => $array_value) { $this->type_cast_helper->set_var($key, $key, gettype($key), $multibyte); - $result[$key] = $this->escape($value, $multibyte); + $result[$key] = $this->escape($array_value, $multibyte); } - $var = $result; + $value = $result; } else { - $this->type_cast_helper->set_var($var, $var, 'string', $multibyte); + $this->type_cast_helper->set_var($value, $value, 'string', $multibyte); } - return $var; + return $value; } } diff --git a/phpBB/phpbb/request/request_interface.php b/phpBB/phpbb/request/request_interface.php index c42c309cc1..9ebd4c25e3 100644 --- a/phpBB/phpbb/request/request_interface.php +++ b/phpBB/phpbb/request/request_interface.php @@ -39,10 +39,10 @@ interface request_interface * @param string $var_name The name of the variable that shall be overwritten * @param mixed $value The value which the variable shall contain. * If this is null the variable will be unset. - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * Specifies which super global shall be changed */ - public function overwrite($var_name, $value, $super_global = \phpbb\request\request_interface::REQUEST); + public function overwrite($var_name, $value, $super_global = request_interface::REQUEST); /** * Central type safe input handling function. @@ -56,13 +56,13 @@ interface request_interface * This function will always return a value of the same type as the default. * @param bool $multibyte If $default is a string this parameter has to be true if the variable may contain any UTF-8 characters * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * Specifies which super global shall be changed * * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the * the same as that of $default. If the variable is not set $default is returned. */ - public function variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST); + public function variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST); /** * Get a variable without trimming strings and without escaping. @@ -78,13 +78,13 @@ interface request_interface * then specifying array("var", 1) as the name will return "a". * @param mixed $default A default value that is returned if the variable was not set. * This function will always return a value of the same type as the default. - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * Specifies which super global shall be changed * * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the * the same as that of $default. If the variable is not set $default is returned. */ - public function raw_variable($var_name, $default, $super_global = \phpbb\request\request_interface::REQUEST); + public function raw_variable($var_name, $default, $super_global = request_interface::REQUEST); /** * Shortcut method to retrieve SERVER variables. @@ -123,12 +123,12 @@ interface request_interface * arrays. * * @param string $var Name of the variable - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * Specifies which super global shall be changed * * @return bool True if the variable was sent as input */ - public function is_set($var, $super_global = \phpbb\request\request_interface::REQUEST); + public function is_set($var, $super_global = request_interface::REQUEST); /** * Checks whether the current request is an AJAX request (XMLHttpRequest) @@ -147,23 +147,23 @@ interface request_interface /** * Returns all variable names for a given super global * - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * The super global from which names shall be taken * * @return array All variable names that are set for the super global. * Pay attention when using these, they are unsanitised! */ - public function variable_names($super_global = \phpbb\request\request_interface::REQUEST); + public function variable_names($super_global = request_interface::REQUEST); /** * Returns the original array of the requested super global * - * @param string $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) + * @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE) * The super global which will be returned * * @return array The original array of the requested super global. */ - public function get_super_global($super_global = \phpbb\request\request_interface::REQUEST); + public function get_super_global($super_global = request_interface::REQUEST); /** * Escape a string variable. diff --git a/phpBB/phpbb/request/type_cast_helper.php b/phpBB/phpbb/request/type_cast_helper.php index 3f793d1c5d..cebaf06316 100644 --- a/phpBB/phpbb/request/type_cast_helper.php +++ b/phpBB/phpbb/request/type_cast_helper.php @@ -72,7 +72,7 @@ class type_cast_helper implements \phpbb\request\type_cast_helper_interface /** * Recursively sets a variable to a given type using {@link set_var set_var} * - * @param string $var The value which shall be sanitised (passed by reference). + * @param mixed $var The value which shall be sanitised (passed by reference). * @param mixed $default Specifies the type $var shall have. * If it is an array and $var is not one, then an empty array is returned. * Otherwise var is cast to the same type, and if $default is an array all diff --git a/phpBB/phpbb/routing/helper.php b/phpBB/phpbb/routing/helper.php index 3d38105aa3..b26fc3fd93 100644 --- a/phpBB/phpbb/routing/helper.php +++ b/phpBB/phpbb/routing/helper.php @@ -83,7 +83,7 @@ class helper * @param array $params String or array of additional url parameters * @param bool $is_amp Is url using & (true) or & (false) * @param string|bool $session_id Possibility to use a custom session id instead of the global one - * @param bool|string $reference_type The type of reference to be generated (one of the constants) + * @param int $reference_type The type of reference to be generated (one of the constants) * @return string The URL already passed through append_sid() */ public function route($route, array $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH) diff --git a/tests/mock/request.php b/tests/mock/request.php index 6a32ba0cf1..1253e40915 100644 --- a/tests/mock/request.php +++ b/tests/mock/request.php @@ -11,7 +11,7 @@ * */ -class phpbb_mock_request implements \phpbb\request\request_interface +class phpbb_mock_request extends \phpbb\request\request { protected $data; From b90f38446618766fef442ced66b7abd4948a14fa Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:52:50 +0100 Subject: [PATCH 12/42] [ticket/16955] Clean up rrouter and fulltext_sphinx PHPBB3-16955 --- phpBB/phpbb/routing/router.php | 4 ++-- phpBB/phpbb/search/backend/fulltext_sphinx.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 18285c06d5..e6f887cca7 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -58,12 +58,12 @@ class router implements RouterInterface protected $php_ext; /** - * @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface|null + * @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface */ protected $matcher; /** - * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface|null + * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface */ protected $generator; diff --git a/phpBB/phpbb/search/backend/fulltext_sphinx.php b/phpBB/phpbb/search/backend/fulltext_sphinx.php index 709690b4f2..5092f67ae5 100644 --- a/phpBB/phpbb/search/backend/fulltext_sphinx.php +++ b/phpBB/phpbb/search/backend/fulltext_sphinx.php @@ -855,6 +855,7 @@ class fulltext_sphinx implements search_backend_interface generate a config for the index. We use a config value fulltext_sphinx_id for this, as it should be unique. */ $config_object = new \phpbb\search\backend\sphinx\config(); + /** @psalm-suppress UndefinedVariable */ $config_data = array( 'source source_phpbb_' . $this->id . '_main' => array( array('type', $this->dbtype . ' # mysql or pgsql'), From 077ceba2a90c83b194dd97e5d630935a55bf34f0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:54:31 +0100 Subject: [PATCH 13/42] [ticket/16955] Improve consistency of user and session class PHPBB3-16955 --- phpBB/phpbb/session.php | 53 ++++++++++++++++++++++----------- phpBB/phpbb/user.php | 48 ++++++++++++++++++++--------- tests/mock/session_testable.php | 2 +- 3 files changed, 70 insertions(+), 33 deletions(-) diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php index e89127800d..d311f3758e 100644 --- a/phpBB/phpbb/session.php +++ b/phpBB/phpbb/session.php @@ -215,6 +215,21 @@ class session return $host; } + /** + * Setup basic user-specific items (style, language, ...) + * + * @param array|string|false $lang_set Lang set(s) to include, false if none shall be included + * @param int|false $style_id Style ID to load, false to load default style + * + * @throws \RuntimeException When called on session and not user instance + * + * @return void + */ + public function setup($lang_set = false, $style_id = false) + { + throw new \RuntimeException('Calling setup on session class is not supported.'); + } + /** * Start session management * @@ -1124,7 +1139,7 @@ class session */ function check_ban($user_id = false, $user_ips = false, $user_email = false, $return = false) { - global $config, $db, $phpbb_dispatcher; + global $db, $phpbb_dispatcher; if (defined('IN_CHECK_BAN') || defined('SKIP_CHECK_BAN')) { @@ -1254,14 +1269,7 @@ class session if ($banned && !$return) { - global $phpbb_root_path, $phpEx; - - // If the session is empty we need to create a valid one... - if (empty($this->session_id)) - { - // This seems to be no longer needed? - #14971 -// $this->session_create(ANONYMOUS); - } + global $phpEx; // Initiate environment ... since it won't be set at this stage $this->setup(); @@ -1295,13 +1303,7 @@ class session } // Determine which message to output - $till_date = ($ban_row['ban_end']) ? $this->format_date($ban_row['ban_end']) : ''; - $message = ($ban_row['ban_end']) ? 'BOARD_BAN_TIME' : 'BOARD_BAN_PERM'; - - $contact_link = phpbb_get_board_contact_link($config, $phpbb_root_path, $phpEx); - $message = sprintf($this->lang[$message], $till_date, '', ''); - $message .= ($ban_row['ban_give_reason']) ? '

' . sprintf($this->lang['BOARD_BAN_REASON'], $ban_row['ban_give_reason']) : ''; - $message .= '

' . $this->lang['BAN_TRIGGERED_BY_' . strtoupper($ban_triggered_by)] . ''; + $message = $this->get_ban_message($ban_row, $ban_triggered_by); // A very special case... we are within the cron script which is not supposed to print out the ban message... show blank page if (defined('IN_CRON')) @@ -1345,6 +1347,19 @@ class session } } + /** + * Get ban info message + * + * @param array $ban_row Ban data row from database + * @param string $ban_triggered_by Ban triggered by; allowed 'user', 'ip', 'email' + * + * @return string + */ + protected function get_ban_message(array $ban_row, string $ban_triggered_by): string + { + return ($ban_row['ban_end']) ? 'BOARD_BAN_TIME' : 'BOARD_BAN_PERM'; + } + /** * Check if ip is blacklisted * This should be called only where absolutely necessary @@ -1355,7 +1370,7 @@ class session * @param string $mode register/post - spamcop for example is omitted for posting * @param string|false $ip the IPv4 address to check * - * @return false if ip is not blacklisted, else an array([checked server], [lookup]) + * @return array|false false if ip is not blacklisted, else an array([checked server], [lookup]) */ function check_dnsbl($mode, $ip = false) { @@ -1680,7 +1695,9 @@ class session $this->data = array_merge($this->data, $sql_ary); - if ($this->data['user_id'] != ANONYMOUS && isset($config['new_member_post_limit']) && $this->data['user_new'] && $config['new_member_post_limit'] <= $this->data['user_posts']) + if ($this->data['user_id'] != ANONYMOUS && isset($config['new_member_post_limit']) + && $this->data['user_new'] && $config['new_member_post_limit'] <= $this->data['user_posts'] + && $this instanceof user) { $this->leave_newly_registered(); } diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index ec3c4b74be..2e7ab22651 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -108,8 +108,13 @@ class user extends \phpbb\session /** * Setup basic user-specific items (style, language, ...) + * + * @param array|string|false $lang_set Lang set(s) to include, false if none shall be included + * @param int|false $style_id Style ID to load, false to load default style + * + * @return void */ - function setup($lang_set = false, $style_id = false) + public function setup($lang_set = false, $style_id = false) { global $db, $request, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; global $phpbb_dispatcher, $phpbb_container; @@ -437,8 +442,6 @@ class user extends \phpbb\session } $this->is_setup_flag = true; - - return; } /** @@ -590,7 +593,7 @@ class user extends \phpbb\session * Format user date * * @param int $gmepoch unix timestamp - * @param string $format date format in date() notation. | used to indicate relative dates, for example |d m Y|, h:i is translated to Today, h:i. + * @param string|false $format date format in date() notation. | used to indicate relative dates, for example |d m Y|, h:i is translated to Today, h:i. * @param bool $forcedate force non-relative date format. * * @return mixed translated date @@ -614,7 +617,7 @@ class user extends \phpbb\session * set $format_date_override to new return value * * @event core.user_format_date_override - * @var DateTimeZone utc Is DateTimeZone in UTC + * @var \DateTimeZone utc Is DateTimeZone in UTC * @var array function_arguments is array comprising a function's argument list * @var string format_date_override Shall we return custom format (string) or not (false) * @since 3.2.1-RC1 @@ -668,12 +671,11 @@ class user extends \phpbb\session /** * Create a \phpbb\datetime object in the context of the current user * - * @since 3.1 * @param string $time String in a format accepted by strtotime(). - * @param DateTimeZone|null $timezone Time zone of the time. + * @param ?\DateTimeZone $timezone Time zone of the time. * @return \phpbb\datetime Date time object linked to the current users locale */ - public function create_datetime($time = 'now', \DateTimeZone $timezone = null) + public function create_datetime(string $time = 'now', ?\DateTimeZone $timezone = null) { $timezone = $timezone ?: $this->create_timezone(); return new $this->datetime($this, $time, $timezone); @@ -684,14 +686,14 @@ class user extends \phpbb\session * * @param string $format Format of the entered date/time * @param string $time Date/time with the timezone applied - * @param DateTimeZone|null $timezone Timezone of the date/time, falls back to timezone of current user - * @return int Returns the unix timestamp + * @param ?\DateTimeZone $timezone Timezone of the date/time, falls back to timezone of current user + * @return string|false Returns the unix timestamp or false if date is invalid */ - public function get_timestamp_from_format($format, $time, \DateTimeZone $timezone = null) + public function get_timestamp_from_format($format, $time, ?\DateTimeZone $timezone = null) { $timezone = $timezone ?: $this->create_timezone(); $date = \DateTime::createFromFormat($format, $time, $timezone); - return ($date !== false) ? $date->format('U') : false; + return $date !== false ? $date->format('U') : false; } /** @@ -760,7 +762,7 @@ class user extends \phpbb\session * Get option bit field from user options. * * @param int $key option key, as defined in $keyoptions property. - * @param int $data bit field value to use, or false to use $this->data['user_options'] + * @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) @@ -774,7 +776,7 @@ class user extends \phpbb\session * * @param int $key Option key, as defined in $keyoptions property. * @param bool $value True to set the option, false to clear the option. - * @param int $data Current bit field value, or false to use $this->data['user_options'] + * @param int|false $data Current bit field value, or false to use $this->data['user_options'] * @return int|bool If $data is false, the bit field is modified and * written back to $this->data['user_options'], and * return value is true if the bit field changed and @@ -865,4 +867,22 @@ class user extends \phpbb\session return $forum_ids; } + + /** + * {@inheritDoc} + */ + protected function get_ban_message(array $ban_row, string $ban_triggered_by): string + { + global $config, $phpbb_root_path, $phpEx; + + $till_date = ($ban_row['ban_end']) ? $this->format_date($ban_row['ban_end']) : ''; + $message = ($ban_row['ban_end']) ? 'BOARD_BAN_TIME' : 'BOARD_BAN_PERM'; + + $contact_link = phpbb_get_board_contact_link($config, $phpbb_root_path, $phpEx); + $message = $this->language->lang($message, $till_date, '', ''); + $message .= ($ban_row['ban_give_reason']) ? '

' . $this->language->lang('BOARD_BAN_REASON', $ban_row['ban_give_reason']) : ''; + $message .= '

' . $this->language->lang('BAN_TRIGGERED_BY_' . strtoupper($ban_triggered_by)) . ''; + + return $message; + } } diff --git a/tests/mock/session_testable.php b/tests/mock/session_testable.php index aa903df0db..84de6a5c6f 100644 --- a/tests/mock/session_testable.php +++ b/tests/mock/session_testable.php @@ -62,7 +62,7 @@ class phpbb_mock_session_testable extends \phpbb\session } } - public function setup() + public function setup($lang_set = false, $style_id = false) { } } From 60c165c3d0e2a2e1cf4c932e6d3286dd6c24e253 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:55:23 +0100 Subject: [PATCH 14/42] [ticket/16955] Clean up storage and template classes PHPBB3-16955 --- phpBB/phpbb/storage/controller/attachment.php | 2 +- phpBB/phpbb/storage/controller/avatar.php | 2 +- phpBB/phpbb/storage/file_info.php | 2 +- phpBB/phpbb/storage/storage.php | 2 +- phpBB/phpbb/template/template.php | 8 -------- phpBB/phpbb/template/twig/extension.php | 8 ++++---- .../phpbb/template/twig/extension/avatar.php | 4 ++-- .../phpbb/template/twig/extension/config.php | 4 ++-- .../phpbb/template/twig/extension/routing.php | 2 +- .../template/twig/extension/username.php | 6 ++---- phpBB/phpbb/template/twig/node/event.php | 2 +- .../twig/tokenparser/defineparser.php | 2 +- phpBB/phpbb/template/twig/twig.php | 19 +++---------------- 13 files changed, 20 insertions(+), 43 deletions(-) diff --git a/phpBB/phpbb/storage/controller/attachment.php b/phpBB/phpbb/storage/controller/attachment.php index 8cfae96905..11d254f24a 100644 --- a/phpBB/phpbb/storage/controller/attachment.php +++ b/phpBB/phpbb/storage/controller/attachment.php @@ -278,7 +278,7 @@ class attachment extends controller $response->headers->set('Content-Disposition', $disposition); // Set expires header for browser cache - $time = new \Datetime(); + $time = new \DateTime(); $response->setExpires($time->modify('+1 year')); return parent::handle($attachment['physical_filename']); diff --git a/phpBB/phpbb/storage/controller/avatar.php b/phpBB/phpbb/storage/controller/avatar.php index aaf347fd79..7055961230 100644 --- a/phpBB/phpbb/storage/controller/avatar.php +++ b/phpBB/phpbb/storage/controller/avatar.php @@ -107,7 +107,7 @@ class avatar extends controller $response->headers->set('Content-Disposition', $disposition); - $time = new \Datetime(); + $time = new \DateTime(); $response->setExpires($time->modify('+1 year')); parent::prepare($response, $file); diff --git a/phpBB/phpbb/storage/file_info.php b/phpBB/phpbb/storage/file_info.php index b57faa42ed..2e93846838 100644 --- a/phpBB/phpbb/storage/file_info.php +++ b/phpBB/phpbb/storage/file_info.php @@ -43,7 +43,7 @@ class file_info /** * Constructor * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $adapter + * @param adapter_interface $adapter * @param string $path */ public function __construct(adapter_interface $adapter, $path) diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index 5689200569..671e9da1a3 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -403,7 +403,7 @@ class storage * * @param string $path The file * - * @throws \phpbb\storage\exception\not_implemented When the adapter doesnt implement the method + * @throws \phpbb\storage\exception\exception When the adapter doesnt implement the method * When the file doesn't exist * * @return \phpbb\storage\file_info Returns file_info object diff --git a/phpBB/phpbb/template/template.php b/phpBB/phpbb/template/template.php index 742dea8d3e..dcc530f37a 100644 --- a/phpBB/phpbb/template/template.php +++ b/phpBB/phpbb/template/template.php @@ -15,14 +15,6 @@ namespace phpbb\template; interface template { - - /** - * Clear the cache - * - * @return \phpbb\template\template - */ - public function clear_cache(); - /** * Sets the template filenames for handles. * diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 6dc3bb2994..f745690089 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -53,7 +53,7 @@ class extension extends \Twig\Extension\AbstractExtension /** * Returns the token parser instance to add to the existing list. * - * @return array An array of \Twig\TokenParser\AbstractTokenParser instances + * @return \Twig\TokenParser\TokenParserInterface[] An array of \Twig\TokenParser\AbstractTokenParser instances */ public function getTokenParsers() { @@ -69,7 +69,7 @@ class extension extends \Twig\Extension\AbstractExtension /** * Returns a list of filters to add to the existing list. * - * @return array An array of filters + * @return \Twig\TwigFilter[] An array of filters */ public function getFilters() { @@ -85,7 +85,7 @@ class extension extends \Twig\Extension\AbstractExtension /** * Returns a list of global functions to add to the existing list. * - * @return array An array of global functions + * @return \Twig\TwigFunction[] An array of global functions */ public function getFunctions() { @@ -100,7 +100,7 @@ class extension extends \Twig\Extension\AbstractExtension /** * Returns a list of operators to add to the existing list. * - * @return array An array of operators + * @return array[] An array of operators */ public function getOperators() { diff --git a/phpBB/phpbb/template/twig/extension/avatar.php b/phpBB/phpbb/template/twig/extension/avatar.php index d8b27fed9f..fb7ec92655 100644 --- a/phpBB/phpbb/template/twig/extension/avatar.php +++ b/phpBB/phpbb/template/twig/extension/avatar.php @@ -30,9 +30,9 @@ class avatar extends AbstractExtension /** * Returns a list of global functions to add to the existing list. * - * @return array An array of global functions + * @return \Twig\TwigFunction[] An array of global functions */ - public function getFunctions() + public function getFunctions(): array { return array( new \Twig\TwigFunction('avatar', array($this, 'get_avatar')), diff --git a/phpBB/phpbb/template/twig/extension/config.php b/phpBB/phpbb/template/twig/extension/config.php index a7f1189d27..ebb4f0c3ca 100644 --- a/phpBB/phpbb/template/twig/extension/config.php +++ b/phpBB/phpbb/template/twig/extension/config.php @@ -43,9 +43,9 @@ class config extends AbstractExtension /** * Returns a list of global functions to add to the existing list. * - * @return array An array of global functions + * @return \Twig\TwigFunction[] An array of global functions */ - public function getFunctions() + public function getFunctions(): array { return array( new \Twig\TwigFunction('config', array($this, 'get_config')), diff --git a/phpBB/phpbb/template/twig/extension/routing.php b/phpBB/phpbb/template/twig/extension/routing.php index 9c404e55d3..3073675d0c 100644 --- a/phpBB/phpbb/template/twig/extension/routing.php +++ b/phpBB/phpbb/template/twig/extension/routing.php @@ -22,7 +22,7 @@ use Twig\TwigFunction; class routing extends AbstractExtension { - /** @var \phpbb\controller\helper */ + /** @var \phpbb\routing\helper */ protected $helper; /** diff --git a/phpBB/phpbb/template/twig/extension/username.php b/phpBB/phpbb/template/twig/extension/username.php index 83cbebe29a..bf99907232 100644 --- a/phpBB/phpbb/template/twig/extension/username.php +++ b/phpBB/phpbb/template/twig/extension/username.php @@ -28,14 +28,12 @@ class username extends AbstractExtension } /** - * Returns a list of global functions to add to the existing list. - * - * @return array An array of global functions + * {@inheritDoc} */ public function getFunctions() { return array( - new \Twig\TwigFunction('username', array($this, 'get_username')), + new \Twig\TwigFunction('username', [$this, 'get_username']), ); } diff --git a/phpBB/phpbb/template/twig/node/event.php b/phpBB/phpbb/template/twig/node/event.php index 76bfc6d127..4eddcbcf38 100644 --- a/phpBB/phpbb/template/twig/node/event.php +++ b/phpBB/phpbb/template/twig/node/event.php @@ -21,7 +21,7 @@ class event extends \Twig\Node\Node */ protected $listener_directory = 'event/'; - /** @var \Twig\Environment */ + /** @var \phpbb\template\twig\environment */ protected $environment; public function __construct(\Twig\Node\Expression\AbstractExpression $expr, \phpbb\template\twig\environment $environment, $lineno, $tag = null) diff --git a/phpBB/phpbb/template/twig/tokenparser/defineparser.php b/phpBB/phpbb/template/twig/tokenparser/defineparser.php index ac98dce421..a8c83c42bc 100644 --- a/phpBB/phpbb/template/twig/tokenparser/defineparser.php +++ b/phpBB/phpbb/template/twig/tokenparser/defineparser.php @@ -23,7 +23,7 @@ class defineparser extends \Twig\TokenParser\AbstractTokenParser * * @return \Twig\Node\Node A Twig\Node instance * @throws \Twig\Error\SyntaxError - * @throws \phpbb\template\twig\node\definenode + * @returns \phpbb\template\twig\node\definenode */ public function parse(\Twig\Token $token) { diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 6f442401ff..1259618175 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -92,27 +92,14 @@ class twig extends \phpbb\template\base } // Add admin namespace - if ($this->path_helper->get_adm_relative_path() !== null && is_dir($this->phpbb_root_path . $this->path_helper->get_adm_relative_path() . 'style/')) + if ($this->path_helper->get_adm_relative_path() !== null + && is_dir($this->phpbb_root_path . $this->path_helper->get_adm_relative_path() . 'style/') + && $this->loader instanceof \Twig\Loader\FilesystemLoader) { $this->loader->setPaths($this->phpbb_root_path . $this->path_helper->get_adm_relative_path() . 'style/', 'admin'); } } - /** - * Clear the cache - * - * @return \phpbb\template\template - */ - public function clear_cache() - { - if (is_dir($this->cachepath)) - { - $this->twig->clearCacheFiles(); - } - - return $this; - } - /** * Get the style tree of the style preferred by the current user * From 6ad0b533d9e8ee5c7045fc21eb55c9a9dec800c2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:56:17 +0100 Subject: [PATCH 15/42] [ticket/16955] Clean up textformatter and textreparser PHPBB3-16955 --- .../phpbb/textformatter/s9e/bbcode_merger.php | 4 +-- phpBB/phpbb/textformatter/s9e/factory.php | 8 ++++-- phpBB/phpbb/textformatter/s9e/parser.php | 3 +- phpBB/phpbb/textformatter/s9e/renderer.php | 19 +++++++------ phpBB/phpbb/textformatter/s9e/utils.php | 28 +++++++++---------- phpBB/phpbb/textreparser/base.php | 3 +- phpBB/phpbb/textreparser/manager.php | 4 +-- .../textreparser/plugins/user_signature.php | 8 +++--- 8 files changed, 42 insertions(+), 35 deletions(-) diff --git a/phpBB/phpbb/textformatter/s9e/bbcode_merger.php b/phpBB/phpbb/textformatter/s9e/bbcode_merger.php index 8173037455..17397800e1 100644 --- a/phpBB/phpbb/textformatter/s9e/bbcode_merger.php +++ b/phpBB/phpbb/textformatter/s9e/bbcode_merger.php @@ -37,8 +37,8 @@ class bbcode_merger * * All of the arrays contain a "usage" element and a "template" element * - * @throws InvalidArgumentException if a definition cannot be interpreted - * @throws RuntimeException if something unexpected occurs + * @throws \InvalidArgumentException if a definition cannot be interpreted + * @throws \RuntimeException if something unexpected occurs * * @param array $without BBCode definition without an attribute * @param array $with BBCode definition with an attribute diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 01cc545a72..4256ec85d9 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -226,8 +226,9 @@ class factory implements \phpbb\textformatter\cache_interface * @event core.text_formatter_s9e_configure_before * @var Configurator configurator Configurator instance * @since 3.2.0-a1 + * @psalm-ignore-var */ - $vars = array('configurator'); + $vars = ['configurator']; extract($this->dispatcher->trigger_event('core.text_formatter_s9e_configure_before', compact($vars))); // Reset the list of allowed schemes @@ -375,8 +376,9 @@ class factory implements \phpbb\textformatter\cache_interface * @event core.text_formatter_s9e_configure_after * @var Configurator configurator Configurator instance * @since 3.2.0-a1 + * @psalm-ignore-var */ - $vars = array('configurator'); + $vars = ['configurator']; extract($this->dispatcher->trigger_event('core.text_formatter_s9e_configure_after', compact($vars))); return $configurator; @@ -444,7 +446,7 @@ class factory implements \phpbb\textformatter\cache_interface } catch (\Exception $e) { - $this->log->add('critical', null, null, 'LOG_BBCODE_CONFIGURATION_ERROR', false, [$usage, $e->getMessage()]); + $this->log->add('critical', ANONYMOUS, '', 'LOG_BBCODE_CONFIGURATION_ERROR', false, [$usage, $e->getMessage()]); } } diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php index cf36879dbe..33f2a0227c 100644 --- a/phpBB/phpbb/textformatter/s9e/parser.php +++ b/phpBB/phpbb/textformatter/s9e/parser.php @@ -65,8 +65,9 @@ class parser implements \phpbb\textformatter\parser_interface * @event core.text_formatter_s9e_parser_setup * @var \phpbb\textformatter\s9e\parser parser This parser service * @since 3.2.0-a1 + * @psalm-ignore-var */ - $vars = array('parser'); + $vars = ['parser']; extract($dispatcher->trigger_event('core.text_formatter_s9e_parser_setup', compact($vars))); } diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 29dbf29afc..855e034b14 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -117,8 +117,9 @@ class renderer implements \phpbb\textformatter\renderer_interface * @event core.text_formatter_s9e_renderer_setup * @var \phpbb\textformatter\s9e\renderer renderer This renderer service * @since 3.2.0-a1 + * @psalm-ignore-var */ - $vars = array('renderer'); + $vars = ['renderer']; extract($dispatcher->trigger_event('core.text_formatter_s9e_renderer_setup', compact($vars))); } @@ -234,16 +235,16 @@ class renderer implements \phpbb\textformatter\renderer_interface /** * {@inheritdoc} */ - public function render($xml) + public function render($text) { if (isset($this->mention_helper)) { - $xml = $this->mention_helper->inject_metadata($xml); + $text = $this->mention_helper->inject_metadata($text); } if (isset($this->quote_helper)) { - $xml = $this->quote_helper->inject_metadata($xml); + $text = $this->quote_helper->inject_metadata($text); } $renderer = $this; @@ -253,13 +254,14 @@ class renderer implements \phpbb\textformatter\renderer_interface * * @event core.text_formatter_s9e_render_before * @var \phpbb\textformatter\s9e\renderer renderer This renderer service - * @var string xml The parsed text, in its XML form + * @var string text The parsed text, in its XML form * @since 3.2.0-a1 + * @psalm-ignore-var */ - $vars = array('renderer', 'xml'); + $vars = ['renderer', 'text']; extract($this->dispatcher->trigger_event('core.text_formatter_s9e_render_before', compact($vars))); - $html = $this->renderer->render($xml); + $html = $this->renderer->render($text); if (isset($this->censor) && $this->viewcensors) { $html = $this->censor->censorHtml($html, true); @@ -272,8 +274,9 @@ class renderer implements \phpbb\textformatter\renderer_interface * @var string html The rendered text's HTML * @var \phpbb\textformatter\s9e\renderer renderer This renderer service * @since 3.2.0-a1 + * @psalm-ignore-var */ - $vars = array('html', 'renderer'); + $vars = ['html', 'renderer']; extract($this->dispatcher->trigger_event('core.text_formatter_s9e_render_after', compact($vars))); return $html; diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index 1c77d89976..9e6e367d24 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -26,15 +26,15 @@ class utils implements \phpbb\textformatter\utils_interface * * NOTE: preserves smilies as text * - * @param string $xml Parsed text + * @param string $text Parsed text * @return string Plain text */ - public function clean_formatting($xml) + public function clean_formatting($text) { // Insert a space before and then remove formatting - $xml = preg_replace('#<[es]>#', ' $0', $xml); + $text = preg_replace('#<[es]>#', ' $0', $text); - return \s9e\TextFormatter\Utils::removeFormatting($xml); + return \s9e\TextFormatter\Utils::removeFormatting($text); } /** @@ -94,19 +94,19 @@ class utils implements \phpbb\textformatter\utils_interface /** * Get a list of quote authors, limited to the outermost quotes * - * @param string $xml Parsed text + * @param string $text Parsed text * @return string[] List of authors */ - public function get_outermost_quote_authors($xml) + public function get_outermost_quote_authors($text) { $authors = array(); - if (strpos($xml, 'loadXML($xml); + $dom->loadXML($text); $xpath = new \DOMXPath($dom); foreach ($xpath->query('//QUOTE[not(ancestor::QUOTE)]/@author') as $author) { @@ -119,25 +119,25 @@ class utils implements \phpbb\textformatter\utils_interface /** * Remove given BBCode and its content, at given nesting depth * - * @param string $xml Parsed text + * @param string $text Parsed text * @param string $bbcode_name BBCode's name * @param integer $depth Minimum nesting depth (number of parents of the same name) * @return string Parsed text */ - public function remove_bbcode($xml, $bbcode_name, $depth = 0) + public function remove_bbcode($text, $bbcode_name, $depth = 0) { - return \s9e\TextFormatter\Utils::removeTag($xml, strtoupper($bbcode_name), $depth); + return \s9e\TextFormatter\Utils::removeTag($text, strtoupper($bbcode_name), $depth); } /** * Return a parsed text to its original form * - * @param string $xml Parsed text + * @param string $text Parsed text * @return string Original plain text */ - public function unparse($xml) + public function unparse($text) { - return \s9e\TextFormatter\Unparser::unparse($xml); + return \s9e\TextFormatter\Unparser::unparse($text); } /** diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index bd7b6c9fc9..c4b344f8db 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -243,7 +243,8 @@ abstract class base implements reparser_interface // generate_text_for_edit() and decode_message() actually return the text as HTML. It has to // be decoded to plain text before it can be reparsed $text = html_entity_decode($unparsed['text'], ENT_QUOTES, 'UTF-8'); - $bitfield = $flags = null; + $bitfield = ''; + $flags = 0; generate_text_for_storage( $text, $unparsed['bbcode_uid'], diff --git a/phpBB/phpbb/textreparser/manager.php b/phpBB/phpbb/textreparser/manager.php index 7ca65d708d..9a7663f938 100644 --- a/phpBB/phpbb/textreparser/manager.php +++ b/phpBB/phpbb/textreparser/manager.php @@ -132,9 +132,9 @@ class manager * If there is no reparser with the specified name, null is returned. * * @param string $name Name of the reparser to look up. - * @return string A reparser service name, or null. + * @return string|null A reparser service name, or null. */ - public function find_reparser($name) + public function find_reparser(string $name) { foreach ($this->reparsers as $service => $reparser) { diff --git a/phpBB/phpbb/textreparser/plugins/user_signature.php b/phpBB/phpbb/textreparser/plugins/user_signature.php index 647d3a7b14..79be5c8282 100644 --- a/phpBB/phpbb/textreparser/plugins/user_signature.php +++ b/phpBB/phpbb/textreparser/plugins/user_signature.php @@ -24,21 +24,21 @@ class user_signature extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function add_missing_fields(array $row) + protected function add_missing_fields(array $record) { if (!isset($this->keyoptions)) { $this->save_keyoptions(); } - $options = $row['user_options']; - $row += array( + $options = $record['user_options']; + $record += array( 'enable_bbcode' => phpbb_optionget($this->keyoptions['sig_bbcode'], $options), 'enable_smilies' => phpbb_optionget($this->keyoptions['sig_smilies'], $options), 'enable_magic_url' => phpbb_optionget($this->keyoptions['sig_links'], $options), ); - return parent::add_missing_fields($row); + return parent::add_missing_fields($record); } /** From 1c02b1a7b5623d3f9e3d6359d7d9d554c81b5883 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:56:51 +0100 Subject: [PATCH 16/42] [ticket/16955] Clean up reset_password and user_loader PHPBB3-16955 --- phpBB/phpbb/ucp/controller/reset_password.php | 8 ++++---- phpBB/phpbb/user_loader.php | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/phpBB/phpbb/ucp/controller/reset_password.php b/phpBB/phpbb/ucp/controller/reset_password.php index 10bc7c2d2f..98ab4ba781 100644 --- a/phpBB/phpbb/ucp/controller/reset_password.php +++ b/phpBB/phpbb/ucp/controller/reset_password.php @@ -22,7 +22,7 @@ use phpbb\exception\http_exception; use phpbb\language\language; use phpbb\log\log_interface; use phpbb\passwords\manager; -use phpbb\request\request_interface; +use phpbb\request\request; use phpbb\template\template; use phpbb\user; use Symfony\Component\HttpFoundation\Response; @@ -53,7 +53,7 @@ class reset_password /** @var manager */ protected $passwords_manager; - /** @var request_interface */ + /** @var request */ protected $request; /** @var template */ @@ -81,7 +81,7 @@ class reset_password * @param language $language * @param log_interface $log * @param manager $passwords_manager - * @param request_interface $request + * @param request $request * @param template $template * @param user $user * @param string $users_table @@ -90,7 +90,7 @@ class reset_password */ public function __construct(config $config, driver_interface $db, dispatcher $dispatcher, helper $helper, language $language, log_interface $log, manager $passwords_manager, - request_interface $request, template $template, user $user, string $users_table, + request $request, template $template, user $user, string $users_table, string $root_path, string $php_ext) { $this->config = $config; diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 18aacce349..5d84a843a3 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -132,10 +132,10 @@ class user_loader * @param bool $query Should we query the database if this user has not yet been loaded? * Typically this should be left as false and you should make sure * you load users ahead of time with load_users() - * @return array|bool Row from the database of the user or Anonymous if the user wasn't loaded/does not exist + * @return array|false Row from the database of the user or Anonymous if the user wasn't loaded/does not exist * or bool False if the anonymous user was not loaded */ - public function get_user($user_id, $query = false) + public function get_user(int $user_id, bool $query = false) { if (isset($this->users[$user_id])) { @@ -162,14 +162,14 @@ class user_loader * colour (for obtaining the user colour) * full (for obtaining a html string representing a coloured link to the users profile) * no_profile (the same as full but forcing no profile link) - * @param string $guest_username Optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. - * @param string $custom_profile_url Optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} + * @param string|bool $guest_username Optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. + * @param string|bool $custom_profile_url Optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} * @param bool $query Should we query the database if this user has not yet been loaded? * Typically this should be left as false and you should make sure * you load users ahead of time with load_users() * @return string */ - public function get_username($user_id, $mode, $guest_username = false, $custom_profile_url = false, $query = false) + public function get_username(int $user_id, string $mode, $guest_username = false, $custom_profile_url = false, bool $query = false): string { if (!($user = $this->get_user($user_id, $query))) { @@ -215,11 +215,11 @@ class user_loader * you load users ahead of time with load_users() * @return array Array with keys 'rank_title', 'rank_img', and 'rank_img_src' */ - public function get_rank($user_id, $query = false) + public function get_rank(int $user_id, bool $query = false): array { if (!($user = $this->get_user($user_id, $query))) { - return ''; + return []; } if (!function_exists('phpbb_get_user_rank')) @@ -233,7 +233,7 @@ class user_loader 'rank_img_src', ); - $user_rank_data = phpbb_get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts'])); + $user_rank_data = phpbb_get_user_rank($user, ($user['user_id'] == ANONYMOUS ? false : $user['user_posts'])); $rank['rank_title'] = $user_rank_data['title']; $rank['rank_img'] = $user_rank_data['img']; $rank['rank_img_src'] = $user_rank_data['img_src']; From d3d53cda0ffdc89c92aaf48305a6ca51bbc36a33 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 14:57:11 +0100 Subject: [PATCH 17/42] [ticket/16955] Update tests to support small changes to docblocks/types PHPBB3-16955 --- .../ext/test/notification/type/test.php | 16 ++++++++-------- tests/template/template_test_case.php | 10 ---------- tests/text_formatter/s9e/factory_test.php | 2 +- tests/text_formatter/s9e/renderer_test.php | 4 ++-- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/tests/notification/ext/test/notification/type/test.php b/tests/notification/ext/test/notification/type/test.php index 7f3b4a4ef1..f325efba6e 100644 --- a/tests/notification/ext/test/notification/type/test.php +++ b/tests/notification/ext/test/notification/type/test.php @@ -28,26 +28,26 @@ class test extends \phpbb\notification\type\base return 'test'; } - public static function get_item_id($post) + public static function get_item_id($type_data) { - return (int) $post['post_id']; + return (int) $type_data['post_id']; } - public static function get_item_parent_id($post) + public static function get_item_parent_id($type_data) { - return (int) $post['topic_id']; + return (int) $type_data['topic_id']; } - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($type_data, $options = array()) { return $this->check_user_notification_options(array(0), $options); } - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($type_data, $pre_create_data = array()) { - $this->notification_time = $post['post_time']; + $this->notification_time = $type_data['post_time']; - parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($type_data, $pre_create_data); } public function create_update_array($type_data) diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 52c76b13a5..fc24600799 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -120,21 +120,11 @@ class phpbb_template_template_test_case extends phpbb_test_case // Test the engine can be used $this->setup_engine(); - $this->template->clear_cache(); - global $phpbb_filesystem; $phpbb_filesystem = new \phpbb\filesystem\filesystem(); } - protected function tearDown(): void - { - if ($this->template) - { - $this->template->clear_cache(); - } - } - protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array()) { $this->template->set_filenames(array('test' => $file)); diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index 6e2de36058..9ab32999d8 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -271,7 +271,7 @@ class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case $log = $this->getMockBuilder('phpbb\\log\\log_interface')->getMock(); $log->expects($this->once()) ->method('add') - ->with('critical', null, null, 'LOG_BBCODE_CONFIGURATION_ERROR', false, ['[x !x]{TEXT}[/x]', 'Cannot interpret the BBCode definition']); + ->with('critical', ANONYMOUS, '', 'LOG_BBCODE_CONFIGURATION_ERROR', false, ['[x !x]{TEXT}[/x]', 'Cannot interpret the BBCode definition']); $container = new phpbb_mock_container_builder; $container->set('log', $log); diff --git a/tests/text_formatter/s9e/renderer_test.php b/tests/text_formatter/s9e/renderer_test.php index d0ca520ea0..51f4f923b4 100644 --- a/tests/text_formatter/s9e/renderer_test.php +++ b/tests/text_formatter/s9e/renderer_test.php @@ -437,8 +437,8 @@ class phpbb_textformatter_s9e_renderer_test extends phpbb_test_case { return isset($vars['renderer']) && $vars['renderer'] instanceof \phpbb\textformatter\s9e\renderer - && isset($vars['xml']) - && $vars['xml'] === '...'; + && isset($vars['text']) + && $vars['text'] === '...'; } public function render_after_event_callback($vars) From 7f61f8b770f58f269336480b260cf88925c6d734 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 16:43:50 +0100 Subject: [PATCH 18/42] [ticket/16955] Clean up filesystem and files classes PHPBB3-16955 --- phpBB/phpbb/file_downloader.php | 2 +- phpBB/phpbb/files/factory.php | 2 +- phpBB/phpbb/files/filespec.php | 2 +- phpBB/phpbb/files/filespec_storage.php | 8 +++--- phpBB/phpbb/files/types/base.php | 14 +++++++--- phpBB/phpbb/files/types/form.php | 8 +++--- phpBB/phpbb/files/types/form_storage.php | 8 +++--- phpBB/phpbb/files/types/local.php | 4 +-- phpBB/phpbb/files/types/local_storage.php | 11 ++++---- phpBB/phpbb/files/types/type_interface.php | 2 +- phpBB/phpbb/files/upload.php | 14 +++++----- phpBB/phpbb/filesystem/filesystem.php | 26 +++++++++---------- .../phpbb/filesystem/filesystem_interface.php | 2 +- phpBB/phpbb/filesystem/helper.php | 4 +-- 14 files changed, 58 insertions(+), 49 deletions(-) diff --git a/phpBB/phpbb/file_downloader.php b/phpBB/phpbb/file_downloader.php index f55b825d2d..75721b0f05 100644 --- a/phpBB/phpbb/file_downloader.php +++ b/phpBB/phpbb/file_downloader.php @@ -77,7 +77,7 @@ class file_downloader $stream_meta_data = stream_get_meta_data($socket); - if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop) + if ($stream_meta_data['timed_out'] || time() >= $timer_stop) { throw new \phpbb\exception\runtime_exception('FSOCK_TIMEOUT'); } diff --git a/phpBB/phpbb/files/factory.php b/phpBB/phpbb/files/factory.php index 84b7cc9449..6f253d548f 100644 --- a/phpBB/phpbb/files/factory.php +++ b/phpBB/phpbb/files/factory.php @@ -46,7 +46,7 @@ class factory try { - $service = $this->container->get($name); + $service = $this->container->get($name) ?? false; } catch (\Exception $e) { diff --git a/phpBB/phpbb/files/filespec.php b/phpBB/phpbb/files/filespec.php index d4f523bf27..1ebfdd7cf5 100644 --- a/phpBB/phpbb/files/filespec.php +++ b/phpBB/phpbb/files/filespec.php @@ -329,7 +329,7 @@ class filespec * Get mime type * * @param string $filename Filename that needs to be checked - * @return string Mime type of supplied filename + * @return string|false Mime type of supplied filename or false if mimetype could not be guessed */ public function get_mimetype($filename) { diff --git a/phpBB/phpbb/files/filespec_storage.php b/phpBB/phpbb/files/filespec_storage.php index 72285305a8..a241f6f949 100644 --- a/phpBB/phpbb/files/filespec_storage.php +++ b/phpBB/phpbb/files/filespec_storage.php @@ -99,7 +99,7 @@ class filespec_storage * * @param array $upload_ary Upload ary * - * @return filespec This instance of the filespec class + * @return filespec_storage This instance of the filespec class */ public function set_upload_ary($upload_ary) { @@ -142,7 +142,7 @@ class filespec_storage * * @param upload $namespace Instance of upload class * - * @return filespec This instance of the filespec class + * @return filespec_storage This instance of the filespec class */ public function set_upload_namespace($namespace) { @@ -166,7 +166,7 @@ class filespec_storage * * @param mixed $error Content for error array * - * @return \phpbb\files\filespec This instance of the filespec class + * @return filespec_storage This instance of the filespec class */ public function set_error($error) { @@ -313,7 +313,7 @@ class filespec_storage * Get mime type * * @param string $filename Filename that needs to be checked - * @return string Mime type of supplied filename + * @return string|false Mime type of supplied filename or false if mimetype could not be guessed */ public function get_mimetype($filename) { diff --git a/phpBB/phpbb/files/types/base.php b/phpBB/phpbb/files/types/base.php index 3313ad040b..eb00b07672 100644 --- a/phpBB/phpbb/files/types/base.php +++ b/phpBB/phpbb/files/types/base.php @@ -27,9 +27,10 @@ abstract class base implements type_interface /** * Check if upload exceeds maximum file size * - * @param \phpbb\files\filespec $file Filespec object + * @template filespec_type of \phpbb\files\filespec|\phpbb\files\filespec_storage + * @param filespec_type $file Filespec object * - * @return \phpbb\files\filespec Returns same filespec instance + * @return filespec_type Returns same filespec instance */ public function check_upload_size($file) { @@ -47,7 +48,14 @@ abstract class base implements type_interface $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB'); } - $file->error[] = (empty($max_filesize)) ? $this->language->lang($this->upload->error_prefix . 'PHP_SIZE_NA') : $this->language->lang($this->upload->error_prefix . 'PHP_SIZE_OVERRUN', $max_filesize, $this->language->lang($unit)); + if (empty($max_filesize)) + { + $file->error[] = $this->language->lang($this->upload->error_prefix . 'PHP_SIZE_NA'); + } + else + { + $file->error[] = $this->language->lang($this->upload->error_prefix . 'PHP_SIZE_OVERRUN', $max_filesize, $this->language->lang($unit)); + } } return $file; diff --git a/phpBB/phpbb/files/types/form.php b/phpBB/phpbb/files/types/form.php index a915476191..88d0fab9ad 100644 --- a/phpBB/phpbb/files/types/form.php +++ b/phpBB/phpbb/files/types/form.php @@ -18,7 +18,7 @@ use phpbb\files\factory; use phpbb\files\filespec; use phpbb\language\language; use phpbb\plupload\plupload; -use phpbb\request\request_interface; +use phpbb\request\request; class form extends base { @@ -28,7 +28,7 @@ class form extends base /** @var plupload */ protected $plupload; - /** @var request_interface */ + /** @var request */ protected $request; /** @@ -38,9 +38,9 @@ class form extends base * @param language $language Language class * @param IniGetWrapper $php_ini ini_get() wrapper * @param plupload $plupload Plupload - * @param request_interface $request Request object + * @param request $request Request object */ - public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, plupload $plupload, request_interface $request) + public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, plupload $plupload, request $request) { $this->factory = $factory; $this->language = $language; diff --git a/phpBB/phpbb/files/types/form_storage.php b/phpBB/phpbb/files/types/form_storage.php index 3024dc83e7..03b9f56119 100644 --- a/phpBB/phpbb/files/types/form_storage.php +++ b/phpBB/phpbb/files/types/form_storage.php @@ -18,7 +18,7 @@ use phpbb\files\factory; use phpbb\files\filespec; use phpbb\language\language; use phpbb\plupload\plupload; -use phpbb\request\request_interface; +use phpbb\request\request; class form_storage extends base { @@ -28,7 +28,7 @@ class form_storage extends base /** @var plupload */ protected $plupload; - /** @var request_interface */ + /** @var request */ protected $request; /** @@ -38,9 +38,9 @@ class form_storage extends base * @param language $language Language class * @param IniGetWrapper $php_ini ini_get() wrapper * @param plupload $plupload Plupload - * @param request_interface $request Request object + * @param request $request Request object */ - public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, plupload $plupload, request_interface $request) + public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, plupload $plupload, request $request) { $this->factory = $factory; $this->language = $language; diff --git a/phpBB/phpbb/files/types/local.php b/phpBB/phpbb/files/types/local.php index ca526c1a01..7bcac0bae0 100644 --- a/phpBB/phpbb/files/types/local.php +++ b/phpBB/phpbb/files/types/local.php @@ -65,8 +65,8 @@ class local extends base $upload = $this->get_upload_ary($source_file, $filedata); /** @var filespec $file */ - $file = $this->factory->get('filespec') - ->set_upload_ary($upload) + $file = $this->factory->get('filespec'); + $file->set_upload_ary($upload) ->set_upload_namespace($this->upload); if ($file->init_error()) diff --git a/phpBB/phpbb/files/types/local_storage.php b/phpBB/phpbb/files/types/local_storage.php index f68d51199e..4329eaf133 100644 --- a/phpBB/phpbb/files/types/local_storage.php +++ b/phpBB/phpbb/files/types/local_storage.php @@ -15,7 +15,7 @@ namespace phpbb\files\types; use bantu\IniGetWrapper\IniGetWrapper; use phpbb\files\factory; -use phpbb\files\filespec; +use phpbb\files\filespec_storage; use phpbb\language\language; use phpbb\request\request_interface; @@ -67,15 +67,15 @@ class local_storage extends base * @param string $source_file Filename of source file * @param array|bool $filedata Array with filedata or false * - * @return filespec Object "filespec" is returned, all further operations can be done with this object + * @return filespec_storage Object "filespec_storage" is returned, all further operations can be done with this object */ protected function local_upload($source_file, $filedata = false) { $upload = $this->get_upload_ary($source_file, $filedata); - /** @var filespec $file */ - $file = $this->factory->get('filespec_storage') - ->set_upload_ary($upload) + /** @var filespec_storage $file */ + $file = $this->factory->get('filespec_storage'); + $file->set_upload_ary($upload) ->set_upload_namespace($this->upload); if ($file->init_error()) @@ -85,6 +85,7 @@ class local_storage extends base } // PHP Upload file size check + /** @var filespec_storage $file */ $file = $this->check_upload_size($file); if (count($file->error)) { diff --git a/phpBB/phpbb/files/types/type_interface.php b/phpBB/phpbb/files/types/type_interface.php index e07078349a..8a20a8eac7 100644 --- a/phpBB/phpbb/files/types/type_interface.php +++ b/phpBB/phpbb/files/types/type_interface.php @@ -21,7 +21,7 @@ interface type_interface * Handle upload for upload types. Arguments passed to this method will be * handled by the upload type classes themselves. * - * @return \phpbb\files\filespec|bool Filespec instance if upload is + * @return \phpbb\files\filespec_storage|\phpbb\files\filespec|bool Filespec instance if upload is * successful or false if not */ public function upload(); diff --git a/phpBB/phpbb/files/upload.php b/phpBB/phpbb/files/upload.php index 1577e67739..9623adec99 100644 --- a/phpBB/phpbb/files/upload.php +++ b/phpBB/phpbb/files/upload.php @@ -14,7 +14,7 @@ namespace phpbb\files; use phpbb\language\language; -use phpbb\request\request_interface; +use phpbb\request\request; /** * File upload class @@ -55,7 +55,7 @@ class upload /** @var language Language class */ protected $language; - /** @var request_interface Request class */ + /** @var request Request class */ protected $request; /** @@ -64,9 +64,9 @@ class upload * @param factory $factory Files factory * @param language $language Language class * @param \bantu\IniGetWrapper\IniGetWrapper $php_ini ini_get() wrapper - * @param request_interface $request Request class + * @param request $request Request class */ - public function __construct(factory $factory, language $language, \bantu\IniGetWrapper\IniGetWrapper $php_ini, request_interface $request) + public function __construct(factory $factory, language $language, \bantu\IniGetWrapper\IniGetWrapper $php_ini, request $request) { $this->factory = $factory; $this->language = $language; @@ -194,7 +194,7 @@ class upload * * @param string $errorcode Error code to assign * - * @return string Error string + * @return string|false Error string or false if error code is not supported * @access public */ public function assign_internal_error($errorcode) @@ -250,7 +250,7 @@ class upload /** * Perform common file checks * - * @param filespec_storage $file Instance of filespec class + * @param filespec_storage|filespec $file Instance of filespec class */ public function common_checks($file) { @@ -296,7 +296,7 @@ class upload /** * Check for allowed dimension * - * @param filespec_storage $file Instance of filespec class + * @param filespec_storage|filespec $file Instance of filespec class * * @return bool True if dimensions are valid or no constraints set, false * if not diff --git a/phpBB/phpbb/filesystem/filesystem.php b/phpBB/phpbb/filesystem/filesystem.php index 2931286811..67b25907b3 100644 --- a/phpBB/phpbb/filesystem/filesystem.php +++ b/phpBB/phpbb/filesystem/filesystem.php @@ -329,7 +329,7 @@ class filesystem implements filesystem_interface /** * {@inheritdoc} */ - public function phpbb_chmod($files, $perms = null, $recursive = false, $force_chmod_link = false) + public function phpbb_chmod($file, $perms = null, $recursive = false, $force_chmod_link = false) { if (is_null($perms)) { @@ -374,26 +374,26 @@ class filesystem implements filesystem_interface { try { - foreach ($this->to_iterator($files) as $file) + foreach ($this->to_iterator($file) as $current_file) { - $file_uid = @fileowner($file); - $file_gid = @filegroup($file); + $file_uid = @fileowner($current_file); + $file_gid = @filegroup($current_file); // Change owner if ($file_uid !== $this->chmod_info['common_owner']) { - $this->chown($file, $this->chmod_info['common_owner'], $recursive); + $this->chown($current_file, $this->chmod_info['common_owner'], $recursive); } // Change group if ($file_gid !== $this->chmod_info['common_group']) { - $this->chgrp($file, $this->chmod_info['common_group'], $recursive); + $this->chgrp($current_file, $this->chmod_info['common_group'], $recursive); } clearstatcache(); - $file_uid = @fileowner($file); - $file_gid = @filegroup($file); + $file_uid = @fileowner($current_file); + $file_gid = @filegroup($current_file); } } catch (filesystem_exception $e) @@ -431,9 +431,9 @@ class filesystem implements filesystem_interface case 'owner': try { - $this->chmod($files, $perms, $recursive, $force_chmod_link); + $this->chmod($file, $perms, $recursive, $force_chmod_link); clearstatcache(); - if ($this->is_readable($files) && $this->is_writable($files)) + if ($this->is_readable($file) && $this->is_writable($file)) { break; } @@ -445,9 +445,9 @@ class filesystem implements filesystem_interface case 'group': try { - $this->chmod($files, $perms, $recursive, $force_chmod_link); + $this->chmod($file, $perms, $recursive, $force_chmod_link); clearstatcache(); - if ((!($perms & self::CHMOD_READ) || $this->is_readable($files, $recursive)) && (!($perms & self::CHMOD_WRITE) || $this->is_writable($files, $recursive))) + if ((!($perms & self::CHMOD_READ) || $this->is_readable($file, $recursive)) && (!($perms & self::CHMOD_WRITE) || $this->is_writable($file, $recursive))) { break; } @@ -458,7 +458,7 @@ class filesystem implements filesystem_interface } case 'other': default: - $this->chmod($files, $perms, $recursive, $force_chmod_link); + $this->chmod($file, $perms, $recursive, $force_chmod_link); break; } } diff --git a/phpBB/phpbb/filesystem/filesystem_interface.php b/phpBB/phpbb/filesystem/filesystem_interface.php index fa7950dec3..0e7967dcfb 100644 --- a/phpBB/phpbb/filesystem/filesystem_interface.php +++ b/phpBB/phpbb/filesystem/filesystem_interface.php @@ -241,7 +241,7 @@ interface filesystem_interface * * @param ?string $path Path to resolve * - * @return string Resolved path + * @return string|false Resolved path or false if path could not be resolved */ public function realpath($path); diff --git a/phpBB/phpbb/filesystem/helper.php b/phpBB/phpbb/filesystem/helper.php index 0843e077ad..9d1c19057e 100644 --- a/phpBB/phpbb/filesystem/helper.php +++ b/phpBB/phpbb/filesystem/helper.php @@ -69,7 +69,7 @@ class helper * Try to resolve real path when PHP's realpath failes to do so * * @param string $path - * @return bool|string + * @return string|false */ protected static function phpbb_own_realpath($path) { @@ -175,7 +175,7 @@ class helper * * @param string $path Path to resolve * - * @return string Resolved path + * @return string|false Resolved path or false if path could not be resolved */ public static function realpath($path) { From e1a3b6b552e9c88d0fabe47b7abd6bd506eb050d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 16:52:17 +0100 Subject: [PATCH 19/42] [ticket/16955] Clean up feed classes PHPBB3-16955 --- phpBB/phpbb/feed/base.php | 4 ++-- phpBB/phpbb/feed/controller/feed.php | 2 +- phpBB/phpbb/feed/feed_interface.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/feed/base.php b/phpBB/phpbb/feed/base.php index d4be0dc592..4b45168dca 100644 --- a/phpBB/phpbb/feed/base.php +++ b/phpBB/phpbb/feed/base.php @@ -329,9 +329,9 @@ abstract class base implements feed_interface } /** - * Returns the SQL query used to retrieve the posts of the feed. + * Sets the SQL query used to retrieve the posts of the feed and returns success state * - * @return string SQL SELECT query + * @return bool True of SQL query was set, false if not */ protected abstract function get_sql(); } diff --git a/phpBB/phpbb/feed/controller/feed.php b/phpBB/phpbb/feed/controller/feed.php index 941177a1ec..d95cda5248 100644 --- a/phpBB/phpbb/feed/controller/feed.php +++ b/phpBB/phpbb/feed/controller/feed.php @@ -298,7 +298,7 @@ class feed * * @return Response * - * @throws exception\feed_exception + * @throws \phpbb\feed\exception\feed_exception */ protected function send_feed_do(feed_interface $feed) { diff --git a/phpBB/phpbb/feed/feed_interface.php b/phpBB/phpbb/feed/feed_interface.php index a548e2f5ea..8d2e7ee3f5 100644 --- a/phpBB/phpbb/feed/feed_interface.php +++ b/phpBB/phpbb/feed/feed_interface.php @@ -52,7 +52,7 @@ interface feed_interface /** * Get the next post in the feed * - * @return array + * @return array|false Item array or false if no next item exists */ public function get_item(); From de9019d64ec57b6c4c5cbcdbdb1a04e6f2d4bf75 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2022 22:46:43 +0100 Subject: [PATCH 20/42] [ticket/16955] Clean up debug, event, and extension classes PHPBB3-16955 --- phpBB/phpbb/debug/error_handler.php | 6 ++++++ phpBB/phpbb/event/md_exporter.php | 6 +++--- phpBB/phpbb/event/php_exporter.php | 5 +++-- phpBB/phpbb/event/recursive_event_filter_iterator.php | 4 +++- phpBB/phpbb/extension/base.php | 10 ++++------ phpBB/phpbb/extension/manager.php | 2 +- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/phpBB/phpbb/debug/error_handler.php b/phpBB/phpbb/debug/error_handler.php index ebd828b97f..f2b00e6365 100644 --- a/phpBB/phpbb/debug/error_handler.php +++ b/phpBB/phpbb/debug/error_handler.php @@ -15,8 +15,14 @@ namespace phpbb\debug; use Symfony\Component\Debug\ErrorHandler; +/** + * @psalm-suppress InvalidExtendClass + */ class error_handler extends ErrorHandler { + /** + * @psalm-suppress MethodSignatureMismatch + */ public function handleError($type, $message, $file, $line) { if ($type === E_USER_WARNING || $type === E_USER_NOTICE) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 8ddc213020..5d2155369a 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -461,7 +461,7 @@ class md_exporter * Validate "Changed" Information * * @param string $changed - * @return string + * @return array{string, string} Changed information containing version and description in respective order * @throws \LogicException */ public function validate_changed($changed) @@ -481,7 +481,7 @@ class md_exporter throw new \LogicException("Invalid changed information found for event '{$this->current_event}'"); } - return array($version, $description); + return [$version, $description]; } /** @@ -492,7 +492,7 @@ class md_exporter */ public function validate_version($version) { - return preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|RC|pl)\d+)?$#', $version); + return (bool) preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|RC|pl)\d+)?$#', $version); } /** diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 720088d3d1..ba8ffbbe36 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -148,8 +148,9 @@ class php_exporter $files = array(); foreach ($iterator as $file_info) { - /** @var \RecursiveDirectoryIterator $file_info */ - $relative_path = $iterator->getInnerIterator()->getSubPathname(); + /** @var \RecursiveDirectoryIterator $inner_iterator */ + $inner_iterator = $iterator->getInnerIterator(); + $relative_path = $inner_iterator->getSubPathname(); $files[] = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path); } diff --git a/phpBB/phpbb/event/recursive_event_filter_iterator.php b/phpBB/phpbb/event/recursive_event_filter_iterator.php index 64e2e56f6a..22a6861522 100644 --- a/phpBB/phpbb/event/recursive_event_filter_iterator.php +++ b/phpBB/phpbb/event/recursive_event_filter_iterator.php @@ -41,7 +41,9 @@ class recursive_event_filter_iterator extends \RecursiveFilterIterator */ public function getChildren() { - return new self($this->getInnerIterator()->getChildren(), $this->root_path); + $inner_iterator = $this->getInnerIterator(); + assert($inner_iterator instanceof \RecursiveIterator); + return new self($inner_iterator->getChildren(), $this->root_path); } /** diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index 57a281fdae..c53d27efd1 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -35,7 +35,7 @@ class base implements \phpbb\extension\extension_interface /** @var string */ protected $extension_path; - /** @var string[]|bool */ + /** @var string[]|false */ private $migrations = false; /** @@ -69,7 +69,7 @@ class base implements \phpbb\extension\extension_interface * Single enable step that installs any included migrations * * @param mixed $old_state State returned by previous call of this method - * @return false Indicates no further steps are required + * @return bool True if further steps are necessary, otherwise false */ public function enable_step($old_state) { @@ -95,7 +95,7 @@ class base implements \phpbb\extension\extension_interface * Single purge step that reverts any included and installed migrations * * @param mixed $old_state State returned by previous call of this method - * @return false Indicates no further steps are required + * @return bool True if further steps are necessary, otherwise false */ public function purge_step($old_state) { @@ -135,8 +135,6 @@ class base implements \phpbb\extension\extension_interface $this->migrator->set_migrations($migrations); - $migrations = $this->migrator->get_migrations(); - - return $migrations; + return $this->migrator->get_migrations(); } } diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 0590adfc98..27257239f6 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -69,7 +69,7 @@ class manager /** * Loads all extension information from the database * - * @return null + * @return void */ public function load_extensions() { From 3bc100c9a0540593ecd32313e8a0d98e2aff4b9c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 14:08:46 +0100 Subject: [PATCH 21/42] [ticket/16955] Add stubs for oci8, pgsql, and sqlite3 PHPBB3-16955 --- build/psalm/stubs/oci8/oci8.php | 19 ++++++++++++++++ build/psalm/stubs/pgsql/pgsql.php | 15 +++++++++++++ build/psalm/stubs/sqlite3/sqlite3.php | 32 +++++++++++++++++++++++++++ build/psalm_bootstrap.php | 4 ++++ psalm.xml | 6 +++++ 5 files changed, 76 insertions(+) create mode 100644 build/psalm/stubs/oci8/oci8.php create mode 100644 build/psalm/stubs/pgsql/pgsql.php create mode 100644 build/psalm/stubs/sqlite3/sqlite3.php diff --git a/build/psalm/stubs/oci8/oci8.php b/build/psalm/stubs/oci8/oci8.php new file mode 100644 index 0000000000..5d05a36fce --- /dev/null +++ b/build/psalm/stubs/oci8/oci8.php @@ -0,0 +1,19 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +/** @link https://php.net/manual/en/oci8.constants.php */ +define('OCI_DEFAULT', 0); + +define('OCI_ASSOC', 1); + +define('OCI_RETURN_NULLS', 4); diff --git a/build/psalm/stubs/pgsql/pgsql.php b/build/psalm/stubs/pgsql/pgsql.php new file mode 100644 index 0000000000..a00b21e46e --- /dev/null +++ b/build/psalm/stubs/pgsql/pgsql.php @@ -0,0 +1,15 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +/** @link https://www.php.net/manual/en/pgsql.constants.php */ +define('PGSQL_CONNECT_FORCE_NEW', 2); diff --git a/build/psalm/stubs/sqlite3/sqlite3.php b/build/psalm/stubs/sqlite3/sqlite3.php new file mode 100644 index 0000000000..a102b39fca --- /dev/null +++ b/build/psalm/stubs/sqlite3/sqlite3.php @@ -0,0 +1,32 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ +class SQLite3 +{ + public function query(string $query) {} +} + +class SQLite3Result +{ + public function fetchArray(int $mode = SQLITE3_BOTH) {} +} + +/** + * @link https://www.php.net/manual/en/sqlite3.constants.php + */ +define('SQLITE3_ASSOC', 1); +define('SQLITE3_NUM', 2); +define('SQLITE3_BOTH', 3); + +define('SQLITE3_OPEN_READONLY', 1); +define('SQLITE3_OPEN_READWRITE', 2); +define('SQLITE3_OPEN_CREATE', 4); diff --git a/build/psalm_bootstrap.php b/build/psalm_bootstrap.php index 4fc5628459..cea4bc64be 100644 --- a/build/psalm_bootstrap.php +++ b/build/psalm_bootstrap.php @@ -23,6 +23,7 @@ require_once $phpbb_root_path . 'includes/startup.php'; $table_prefix = 'phpbb_'; require_once $phpbb_root_path . 'includes/constants.php'; require_once $phpbb_root_path . 'phpbb/class_loader.' . $phpEx; +require_once $phpbb_root_path . 'includes/acp/acp_database.' . $phpEx; require_once $phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx; require_once $phpbb_root_path . 'includes/functions.' . $phpEx; require_once $phpbb_root_path . 'includes/functions_acp.' . $phpEx; @@ -46,6 +47,9 @@ require_once $phpbb_root_path . 'includes/compatibility_globals.' . $phpEx; $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', $phpbb_root_path . 'phpbb/', "php"); $phpbb_class_loader->register(); +// Include files that require class loader to be initialized +require_once $phpbb_root_path . 'includes/acp/auth.' . $phpEx; + class phpbb_cache_container extends \Symfony\Component\DependencyInjection\Container { } diff --git a/psalm.xml b/psalm.xml index 02160bcadf..0fbf33cdef 100644 --- a/psalm.xml +++ b/psalm.xml @@ -20,4 +20,10 @@ + + + + + + From 948023078bdab21db27e680ec93357d77a4fe231 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 14:13:23 +0100 Subject: [PATCH 22/42] [ticket/16955] Clean up code in db classes PHPBB3-16955 --- phpBB/phpbb/db/doctrine/oci8/connection.php | 2 +- phpBB/phpbb/db/doctrine/table_helper.php | 2 +- phpBB/phpbb/db/doctrine/type_converter.php | 6 +- phpBB/phpbb/db/driver/driver.php | 91 ++++++++++++++++++- phpBB/phpbb/db/driver/driver_interface.php | 8 +- phpBB/phpbb/db/driver/factory.php | 12 ++- phpBB/phpbb/db/driver/mssql_base.php | 19 +--- phpBB/phpbb/db/driver/mssql_odbc.php | 52 +++++------ phpBB/phpbb/db/driver/mssqlnative.php | 48 ++++------ phpBB/phpbb/db/driver/mysql_base.php | 35 ++----- phpBB/phpbb/db/driver/mysqli.php | 45 +++------ phpBB/phpbb/db/driver/oracle.php | 59 +++++------- phpBB/phpbb/db/driver/postgres.php | 74 ++++----------- phpBB/phpbb/db/driver/sqlite3.php | 61 ++++--------- phpBB/phpbb/db/extractor/factory.php | 17 ++-- phpBB/phpbb/db/extractor/mssql_extractor.php | 4 +- phpBB/phpbb/db/extractor/oracle_extractor.php | 6 +- .../data/v310/soft_delete_mod_convert.php | 4 +- .../data/v31x/remove_duplicate_migrations.php | 8 +- phpBB/phpbb/db/migration/tool/config.php | 8 +- phpBB/phpbb/db/migration/tool/config_text.php | 4 +- phpBB/phpbb/db/migration/tool/module.php | 2 +- phpBB/phpbb/db/migration/tool/permission.php | 19 ++-- .../db/migration/tool/tool_interface.php | 2 +- phpBB/phpbb/db/migrator.php | 13 +-- phpBB/phpbb/db/tools/doctrine.php | 3 +- 26 files changed, 277 insertions(+), 327 deletions(-) diff --git a/phpBB/phpbb/db/doctrine/oci8/connection.php b/phpBB/phpbb/db/doctrine/oci8/connection.php index 6f7f0aa3b9..34ed744e9d 100644 --- a/phpBB/phpbb/db/doctrine/oci8/connection.php +++ b/phpBB/phpbb/db/doctrine/oci8/connection.php @@ -68,7 +68,7 @@ class connection implements DriverConnection /** * {@inheritDoc} */ - public function lastInsertId($name = null): ?string + public function lastInsertId($name = null) { return $this->wrapped->lastInsertId($name); } diff --git a/phpBB/phpbb/db/doctrine/table_helper.php b/phpBB/phpbb/db/doctrine/table_helper.php index f6fde0fd2d..b14571c9f8 100644 --- a/phpBB/phpbb/db/doctrine/table_helper.php +++ b/phpBB/phpbb/db/doctrine/table_helper.php @@ -21,7 +21,7 @@ class table_helper * * @param array $column_data Column data. * - * @return array A pair of type and array of column options. + * @return array{string, array} A pair of type and array of column options. */ public static function convert_column_data(array $column_data, string $dbms_layer): array { diff --git a/phpBB/phpbb/db/doctrine/type_converter.php b/phpBB/phpbb/db/doctrine/type_converter.php index c03c3bd2c8..61da22eaf1 100644 --- a/phpBB/phpbb/db/doctrine/type_converter.php +++ b/phpBB/phpbb/db/doctrine/type_converter.php @@ -54,7 +54,7 @@ class type_converter * * @param string $type Legacy type name * - * @return array Pair of type name and options. + * @return array{string, array} Pair of type name and options. */ public static function convert(string $type, string $dbms): array { @@ -73,7 +73,7 @@ class type_converter * @param string $type Legacy type name. * @param int $length Type length. * - * @return array Pair of type name and options. + * @return array{string, array} Pair of type name and options. */ private static function mapWithLength(string $type, int $length): array { @@ -107,7 +107,7 @@ class type_converter * * @param string $type Type name. * - * @return array Pair of type name and an array of options. + * @return array{string, array} Pair of type name and an array of options. */ private static function mapType(string $type, string $dbms): array { diff --git a/phpBB/phpbb/db/driver/driver.php b/phpBB/phpbb/db/driver/driver.php index cd9f1f058e..a16c6260f4 100644 --- a/phpBB/phpbb/db/driver/driver.php +++ b/phpBB/phpbb/db/driver/driver.php @@ -31,6 +31,9 @@ abstract class driver implements driver_interface var $html_hold = ''; var $sql_report = ''; + /** @var string Last query text */ + protected $last_query_text = ''; + var $persistency = false; var $user = ''; var $server = ''; @@ -279,6 +282,13 @@ abstract class driver implements driver_interface return $result; } + /** + * Close sql connection + * + * @return bool False if failure + */ + abstract protected function _sql_close(): bool; + /** * {@inheritDoc} */ @@ -296,6 +306,18 @@ abstract class driver implements driver_interface return $this->_sql_query_limit($query, $total, $offset, $cache_ttl); } + /** + * Build LIMIT query + * + * @param string $query The SQL query to execute + * @param int $total The number of rows to select + * @param int $offset + * @param int $cache_ttl Either 0 to avoid caching or + * the time in seconds which the result shall be kept in cache + * @return mixed Buffered, seekable result handle, false on error + */ + abstract protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0); + /** * {@inheritDoc} */ @@ -404,6 +426,18 @@ abstract class driver implements driver_interface return $this->_sql_like_expression('LIKE \'' . $this->sql_escape($expression) . '\''); } + /** + * Build LIKE expression + * + * @param string $expression Base expression + * + * @return string LIKE expression + */ + protected function _sql_like_expression(string $expression): string + { + return $expression; + } + /** * {@inheritDoc} */ @@ -415,6 +449,18 @@ abstract class driver implements driver_interface return $this->_sql_not_like_expression('NOT LIKE \'' . $this->sql_escape($expression) . '\''); } + /** + * Build NOT LIKE expression + * + * @param string $expression Base expression + * + * @return string NOT LIKE expression + */ + protected function _sql_not_like_expression(string $expression): string + { + return $expression; + } + /** * {@inheritDoc} */ @@ -510,12 +556,22 @@ abstract class driver implements driver_interface return $result; } + /** + * SQL Transaction + * + * @param string $status Should be one of the following strings: + * begin, commit, rollback + * + * @return bool Success/failure of the transaction query + */ + abstract protected function _sql_transaction(string $status = 'begin'): bool; + /** * {@inheritDoc} */ - function sql_build_array($query, $assoc_ary = false) + function sql_build_array($query, $assoc_ary = []) { - if (!is_array($assoc_ary)) + if (!count($assoc_ary)) { return false; } @@ -836,6 +892,18 @@ abstract class driver implements driver_interface return $sql; } + /** + * Build db-specific query data + * + * @param string $stage Query stage, can be 'FROM' or 'WHERE' + * @param string|array $data A string containing the CROSS JOIN query or an array of WHERE clauses + * + * @return string|array The db-specific query fragment + */ + protected function _sql_custom_build(string $stage, $data) + { + return $data; + } protected function _process_boolean_tree_first($operations_ary) { @@ -1017,7 +1085,7 @@ abstract class driver implements driver_interface global $msg_long_text; $msg_long_text = $message; - trigger_error(false, E_USER_ERROR); + trigger_error('', E_USER_ERROR); } trigger_error($message, E_USER_ERROR); @@ -1031,6 +1099,13 @@ abstract class driver implements driver_interface return $this->sql_error_returned; } + /** + * Return sql error array + * + * @return array{message: string, code: int|string} SQL error array with message and error code + */ + abstract protected function _sql_error(): array; + /** * {@inheritDoc} */ @@ -1216,6 +1291,16 @@ abstract class driver implements driver_interface return true; } + /** + * Build db-specific report + * + * @param string $mode 'start' to add to report, 'fromcache' to output it + * @param string $query Query to add to sql report + * + * @return void + */ + abstract protected function _sql_report(string $mode, string $query = ''): void; + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/db/driver/driver_interface.php b/phpBB/phpbb/db/driver/driver_interface.php index 6d95f61c16..69a22b3f41 100644 --- a/phpBB/phpbb/db/driver/driver_interface.php +++ b/phpBB/phpbb/db/driver/driver_interface.php @@ -180,7 +180,7 @@ interface driver_interface * Return on error or display error message * * @param bool $fail Should we return on errors, or stop - * @return null + * @return void */ public function sql_return_on_error($fail = false); @@ -190,9 +190,9 @@ interface driver_interface * @param string $query Should be on of the following strings: * INSERT, INSERT_SELECT, UPDATE, SELECT, DELETE * @param array $assoc_ary Array with "column => value" pairs - * @return string A SQL statement like "c1 = 'a' AND c2 = 'b'" + * @return string|false A SQL statement like "c1 = 'a' AND c2 = 'b'", false on invalid assoc_ary */ - public function sql_build_array($query, $assoc_ary = array()); + public function sql_build_array($query, $assoc_ary = []); /** * Fetch all rows @@ -299,7 +299,7 @@ interface driver_interface * Add to query count * * @param bool $cached Is this query cached? - * @return null + * @return void */ public function sql_add_num_queries($cached = false); diff --git a/phpBB/phpbb/db/driver/factory.php b/phpBB/phpbb/db/driver/factory.php index b2a5707120..d282aa78e6 100644 --- a/phpBB/phpbb/db/driver/factory.php +++ b/phpBB/phpbb/db/driver/factory.php @@ -49,7 +49,9 @@ class factory implements driver_interface { if ($this->driver === null) { - $this->driver = $this->container->get('dbal.conn.driver'); + /** @var driver_interface $driver */ + $driver = $this->container->get('dbal.conn.driver'); + $this->driver = $driver; } return $this->driver; @@ -238,13 +240,13 @@ class factory implements driver_interface */ public function sql_return_on_error($fail = false) { - return $this->get_driver()->sql_return_on_error($fail); + $this->get_driver()->sql_return_on_error($fail); } /** * {@inheritdoc} */ - public function sql_build_array($query, $assoc_ary = array()) + public function sql_build_array($query, $assoc_ary = []) { return $this->get_driver()->sql_build_array($query, $assoc_ary); } @@ -326,7 +328,7 @@ class factory implements driver_interface */ public function sql_add_num_queries($cached = false) { - return $this->get_driver()->sql_add_num_queries($cached); + $this->get_driver()->sql_add_num_queries($cached); } /** @@ -374,7 +376,7 @@ class factory implements driver_interface */ public function sql_freeresult($query_id = false) { - return $this->get_driver()->sql_freeresult($query_id); + $this->get_driver()->sql_freeresult($query_id); } /** diff --git a/phpBB/phpbb/db/driver/mssql_base.php b/phpBB/phpbb/db/driver/mssql_base.php index c48f7d42a6..747df00bee 100644 --- a/phpBB/phpbb/db/driver/mssql_base.php +++ b/phpBB/phpbb/db/driver/mssql_base.php @@ -43,19 +43,17 @@ abstract class mssql_base extends \phpbb\db\driver\driver } /** - * Build LIKE expression - * @access private + * {@inheritDoc} */ - function _sql_like_expression($expression) + protected function _sql_like_expression(string $expression): string { return $expression . " ESCAPE '\\'"; } /** - * Build NOT LIKE expression - * @access private + * {@inheritDoc} */ - function _sql_not_like_expression($expression) + protected function _sql_not_like_expression(string $expression): string { return $expression . " ESCAPE '\\'"; } @@ -68,15 +66,6 @@ abstract class mssql_base extends \phpbb\db\driver\driver return 'CONVERT(BIGINT, ' . $expression . ')'; } - /** - * Build db-specific query data - * @access private - */ - function _sql_custom_build($stage, $data) - { - return $data; - } - /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/db/driver/mssql_odbc.php b/phpBB/phpbb/db/driver/mssql_odbc.php index 06cdce7a15..211b98fc7e 100644 --- a/phpBB/phpbb/db/driver/mssql_odbc.php +++ b/phpBB/phpbb/db/driver/mssql_odbc.php @@ -24,7 +24,6 @@ namespace phpbb\db\driver; */ class mssql_odbc extends \phpbb\db\driver\mssql_base { - var $last_query_text = ''; var $connect_error = ''; /** @@ -112,31 +111,27 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base if ($raw) { - return $this->sql_server_version; + return (string) $this->sql_server_version; } return ($this->sql_server_version) ? 'MSSQL (ODBC)
' . $this->sql_server_version : 'MSSQL (ODBC)'; } /** - * SQL Transaction - * @access private + * {@inheritDoc} */ - function _sql_transaction($status = 'begin') + protected function _sql_transaction(string $status = 'begin'): bool { switch ($status) { case 'begin': - return @odbc_exec($this->db_connect_id, 'BEGIN TRANSACTION'); - break; + return (bool) @odbc_exec($this->db_connect_id, 'BEGIN TRANSACTION'); case 'commit': - return @odbc_exec($this->db_connect_id, 'COMMIT TRANSACTION'); - break; + return (bool) @odbc_exec($this->db_connect_id, 'COMMIT TRANSACTION'); case 'rollback': - return @odbc_exec($this->db_connect_id, 'ROLLBACK TRANSACTION'); - break; + return (bool) @odbc_exec($this->db_connect_id, 'ROLLBACK TRANSACTION'); } return true; @@ -209,9 +204,9 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base } /** - * Build LIMIT query - */ - function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + * {@inheritDoc} + */ + protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0) { $this->query_result = false; @@ -303,23 +298,19 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base if ($cache && !is_object($query_id) && $cache->sql_exists($query_id)) { - return $cache->sql_freeresult($query_id); + $cache->sql_freeresult($query_id); } - - if (isset($this->open_queries[(int) $query_id])) + else if (isset($this->open_queries[(int) $query_id])) { unset($this->open_queries[(int) $query_id]); - return odbc_free_result($query_id); + odbc_free_result($query_id); } - - return false; } /** - * return sql error array - * @access private + * {@inheritDoc} */ - function _sql_error() + protected function _sql_error(): array { if (function_exists('odbc_errormsg')) { @@ -340,19 +331,18 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base } /** - * Close sql connection - * @access private - */ - function _sql_close() + * {@inheritDoc} + */ + protected function _sql_close(): bool { - return @odbc_close($this->db_connect_id); + @odbc_close($this->db_connect_id); + return true; } /** - * Build db-specific report - * @access private + * {@inheritDoc} */ - function _sql_report($mode, $query = '') + protected function _sql_report(string $mode, string $query = ''): void { switch ($mode) { diff --git a/phpBB/phpbb/db/driver/mssqlnative.php b/phpBB/phpbb/db/driver/mssqlnative.php index 30ef9d9bc4..62a5f51772 100644 --- a/phpBB/phpbb/db/driver/mssqlnative.php +++ b/phpBB/phpbb/db/driver/mssqlnative.php @@ -23,10 +23,12 @@ namespace phpbb\db\driver; class mssqlnative extends \phpbb\db\driver\mssql_base { var $m_insert_id = null; - var $last_query_text = ''; var $query_options = array(); var $connect_error = ''; + /** @var string|false Last error result or false if no last error set */ + private $last_error_result = false; + /** * {@inheritDoc} */ @@ -92,24 +94,20 @@ class mssqlnative extends \phpbb\db\driver\mssql_base } /** - * SQL Transaction - * @access private + * {@inheritDoc} */ - function _sql_transaction($status = 'begin') + protected function _sql_transaction(string $status = 'begin'): bool { switch ($status) { case 'begin': return sqlsrv_begin_transaction($this->db_connect_id); - break; case 'commit': return sqlsrv_commit($this->db_connect_id); - break; case 'rollback': return sqlsrv_rollback($this->db_connect_id); - break; } return true; } @@ -182,9 +180,9 @@ class mssqlnative extends \phpbb\db\driver\mssql_base } /** - * Build LIMIT query - */ - function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + * {@inheritDoc} + */ + protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0) { $this->query_result = false; @@ -280,7 +278,7 @@ class mssqlnative extends \phpbb\db\driver\mssql_base if ($result_id) { $row = sqlsrv_fetch_array($result_id); - $id = $row[0]; + $id = isset($row[0]) ? (int) $row[0] : false; sqlsrv_free_stmt($result_id); return $id; } @@ -304,23 +302,19 @@ class mssqlnative extends \phpbb\db\driver\mssql_base if ($cache && !is_object($query_id) && $cache->sql_exists($query_id)) { - return $cache->sql_freeresult($query_id); + $cache->sql_freeresult($query_id); } - - if (isset($this->open_queries[(int) $query_id])) + else if (isset($this->open_queries[(int) $query_id])) { unset($this->open_queries[(int) $query_id]); - return sqlsrv_free_stmt($query_id); + sqlsrv_free_stmt($query_id); } - - return false; } /** - * return sql error array - * @access private + * {@inheritDoc} */ - function _sql_error() + protected function _sql_error(): array { if (function_exists('sqlsrv_errors')) { @@ -342,7 +336,7 @@ class mssqlnative extends \phpbb\db\driver\mssql_base } else { - $error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array(); + $error = $this->last_error_result ?: ''; } $error = array( @@ -362,19 +356,17 @@ class mssqlnative extends \phpbb\db\driver\mssql_base } /** - * Close sql connection - * @access private - */ - function _sql_close() + * {@inheritDoc} + */ + protected function _sql_close(): bool { return @sqlsrv_close($this->db_connect_id); } /** - * Build db-specific report - * @access private + * {@inheritDoc} */ - function _sql_report($mode, $query = '') + protected function _sql_report(string $mode, string $query = ''): void { switch ($mode) { diff --git a/phpBB/phpbb/db/driver/mysql_base.php b/phpBB/phpbb/db/driver/mysql_base.php index 5e0b359134..481d4c7992 100644 --- a/phpBB/phpbb/db/driver/mysql_base.php +++ b/phpBB/phpbb/db/driver/mysql_base.php @@ -27,9 +27,9 @@ abstract class mysql_base extends \phpbb\db\driver\driver } /** - * Build LIMIT query - */ - function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + * {@inheritDoc} + */ + protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0) { $this->query_result = false; @@ -103,34 +103,13 @@ abstract class mysql_base extends \phpbb\db\driver\driver } /** - * Build LIKE expression - * @access private + * {@inheritDoc} */ - function _sql_like_expression($expression) + protected function _sql_custom_build(string $stage, $data) { - return $expression; - } - - /** - * Build NOT LIKE expression - * @access private - */ - function _sql_not_like_expression($expression) - { - return $expression; - } - - /** - * Build db-specific query data - * @access private - */ - function _sql_custom_build($stage, $data) - { - switch ($stage) + if ($stage === 'FROM' && is_string($data)) { - case 'FROM': - $data = '(' . $data . ')'; - break; + $data = '(' . $data . ')'; } return $data; diff --git a/phpBB/phpbb/db/driver/mysqli.php b/phpBB/phpbb/db/driver/mysqli.php index 1b7f6252f6..e2f6d20033 100644 --- a/phpBB/phpbb/db/driver/mysqli.php +++ b/phpBB/phpbb/db/driver/mysqli.php @@ -69,7 +69,7 @@ class mysqli extends \phpbb\db\driver\mysql_base if ($this->db_connect_id && $this->dbname != '') { // Disable loading local files on client side - @mysqli_options($this->db_connect_id, MYSQLI_OPT_LOCAL_INFILE, false); + @mysqli_options($this->db_connect_id, MYSQLI_OPT_LOCAL_INFILE, 0); /* * As of PHP 8.1 MySQLi default error mode is set to MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT @@ -143,32 +143,28 @@ class mysqli extends \phpbb\db\driver\mysql_base } } - return ($raw) ? $this->sql_server_version : 'MySQL(i) ' . $this->sql_server_version; + return ($raw) ? (string) $this->sql_server_version : 'MySQL(i) ' . $this->sql_server_version; } /** - * SQL Transaction - * @access private + * {@inheritDoc} */ - function _sql_transaction($status = 'begin') + protected function _sql_transaction(string $status = 'begin'): bool { switch ($status) { case 'begin': return @mysqli_autocommit($this->db_connect_id, false); - break; case 'commit': $result = @mysqli_commit($this->db_connect_id); @mysqli_autocommit($this->db_connect_id, true); return $result; - break; case 'rollback': $result = @mysqli_rollback($this->db_connect_id); @mysqli_autocommit($this->db_connect_id, true); return $result; - break; } return true; @@ -293,7 +289,7 @@ class mysqli extends \phpbb\db\driver\mysql_base */ function sql_nextid() { - return ($this->db_connect_id) ? @mysqli_insert_id($this->db_connect_id) : false; + return ($this->db_connect_id) ? (int) @mysqli_insert_id($this->db_connect_id) : false; } /** @@ -310,20 +306,12 @@ class mysqli extends \phpbb\db\driver\mysql_base if ($cache && !is_object($query_id) && $cache->sql_exists($query_id)) { - return $cache->sql_freeresult($query_id); + $cache->sql_freeresult($query_id); } - - if (!$query_id) + else if ($query_id && $query_id !== true) { - return false; + mysqli_free_result($query_id); } - - if ($query_id === true) - { - return true; - } - - return mysqli_free_result($query_id); } /** @@ -335,10 +323,9 @@ class mysqli extends \phpbb\db\driver\mysql_base } /** - * return sql error array - * @access private + * {@inheritDoc} */ - function _sql_error() + protected function _sql_error(): array { if ($this->db_connect_id) { @@ -366,19 +353,17 @@ class mysqli extends \phpbb\db\driver\mysql_base } /** - * Close sql connection - * @access private - */ - function _sql_close() + * {@inheritDoc} + */ + protected function _sql_close(): bool { return @mysqli_close($this->db_connect_id); } /** - * Build db-specific report - * @access private + * {@inheritDoc} */ - function _sql_report($mode, $query = '') + protected function _sql_report(string $mode, string $query = ''): void { static $test_prof; diff --git a/phpBB/phpbb/db/driver/oracle.php b/phpBB/phpbb/db/driver/oracle.php index 04af0a0a9c..b777dcfc72 100644 --- a/phpBB/phpbb/db/driver/oracle.php +++ b/phpBB/phpbb/db/driver/oracle.php @@ -18,9 +18,11 @@ namespace phpbb\db\driver; */ class oracle extends \phpbb\db\driver\driver { - var $last_query_text = ''; var $connect_error = ''; + /** @var array|false Last error result or false if no last error set */ + private $last_error_result = false; + /** * {@inheritDoc} */ @@ -107,24 +109,20 @@ class oracle extends \phpbb\db\driver\driver } /** - * SQL Transaction - * @access private + * {@inheritDoc} */ - function _sql_transaction($status = 'begin') + protected function _sql_transaction(string $status = 'begin'): bool { switch ($status) { case 'begin': return true; - break; case 'commit': return @oci_commit($this->db_connect_id); - break; case 'rollback': return @oci_rollback($this->db_connect_id); - break; } return true; @@ -465,9 +463,9 @@ class oracle extends \phpbb\db\driver\driver } /** - * Build LIMIT query + * {@inheritDoc} */ - function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0) { $this->query_result = false; @@ -621,16 +619,13 @@ class oracle extends \phpbb\db\driver\driver if ($cache && !is_object($query_id) && $cache->sql_exists($query_id)) { - return $cache->sql_freeresult($query_id); + $cache->sql_freeresult($query_id); } - - if (isset($this->open_queries[(int) $query_id])) + else if (isset($this->open_queries[(int) $query_id])) { unset($this->open_queries[(int) $query_id]); - return oci_free_statement($query_id); + oci_free_statement($query_id); } - - return false; } /** @@ -642,28 +637,21 @@ class oracle extends \phpbb\db\driver\driver } /** - * Build LIKE expression - * @access private + * {@inheritDoc} */ - function _sql_like_expression($expression) + protected function _sql_like_expression(string $expression): string { return $expression . " ESCAPE '\\'"; } /** - * Build NOT LIKE expression - * @access private + * {@inheritDoc} */ - function _sql_not_like_expression($expression) + protected function _sql_not_like_expression(string $expression): string { return $expression . " ESCAPE '\\'"; } - function _sql_custom_build($stage, $data) - { - return $data; - } - function _sql_bit_and($column_name, $bit, $compare = '') { return 'BITAND(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : ''); @@ -675,10 +663,9 @@ class oracle extends \phpbb\db\driver\driver } /** - * return sql error array - * @access private + * {@inheritDoc} */ - function _sql_error() + protected function _sql_error(): array { if (function_exists('oci_error')) { @@ -692,7 +679,7 @@ class oracle extends \phpbb\db\driver\driver } else { - $error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array(); + $error = $this->last_error_result ?: ['message' => '', 'code' => '']; } } else @@ -707,19 +694,17 @@ class oracle extends \phpbb\db\driver\driver } /** - * Close sql connection - * @access private - */ - function _sql_close() + * {@inheritDoc} + */ + protected function _sql_close(): bool { return @oci_close($this->db_connect_id); } /** - * Build db-specific report - * @access private + * {@inheritDoc} */ - function _sql_report($mode, $query = '') + protected function _sql_report(string $mode, string $query = ''): void { switch ($mode) { diff --git a/phpBB/phpbb/db/driver/postgres.php b/phpBB/phpbb/db/driver/postgres.php index 3ee4b2b00e..63ebdbf994 100644 --- a/phpBB/phpbb/db/driver/postgres.php +++ b/phpBB/phpbb/db/driver/postgres.php @@ -20,7 +20,6 @@ namespace phpbb\db\driver; class postgres extends \phpbb\db\driver\driver { var $multi_insert = true; - var $last_query_text = ''; var $connect_error = ''; /** @@ -137,28 +136,24 @@ class postgres extends \phpbb\db\driver\driver } } - return ($raw) ? $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version; + return ($raw) ? (string) $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version; } /** - * SQL Transaction - * @access private + * {@inheritDoc} */ - function _sql_transaction($status = 'begin') + protected function _sql_transaction(string $status = 'begin'): bool { switch ($status) { case 'begin': - return @pg_query($this->db_connect_id, 'BEGIN'); - break; + return @pg_query($this->db_connect_id, 'BEGIN') !== false; case 'commit': - return @pg_query($this->db_connect_id, 'COMMIT'); - break; + return @pg_query($this->db_connect_id, 'COMMIT') !== false; case 'rollback': - return @pg_query($this->db_connect_id, 'ROLLBACK'); - break; + return @pg_query($this->db_connect_id, 'ROLLBACK') !== false; } return true; @@ -233,18 +228,9 @@ class postgres extends \phpbb\db\driver\driver } /** - * Build db-specific query data - * @access private + * {@inheritDoc} */ - function _sql_custom_build($stage, $data) - { - return $data; - } - - /** - * Build LIMIT query - */ - function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0) { $this->query_result = false; @@ -385,16 +371,13 @@ class postgres extends \phpbb\db\driver\driver $safe_query_id = $this->clean_query_id($query_id); if ($cache && !is_object($query_id) && $cache->sql_exists($safe_query_id)) { - return $cache->sql_freeresult($safe_query_id); + $cache->sql_freeresult($safe_query_id); } - - if (isset($this->open_queries[$safe_query_id])) + else if (isset($this->open_queries[$safe_query_id])) { unset($this->open_queries[$safe_query_id]); - return pg_free_result($query_id); + pg_free_result($query_id); } - - return false; } /** @@ -405,24 +388,6 @@ class postgres extends \phpbb\db\driver\driver return @pg_escape_string($msg); } - /** - * Build LIKE expression - * @access private - */ - function _sql_like_expression($expression) - { - return $expression; - } - - /** - * Build NOT LIKE expression - * @access private - */ - function _sql_not_like_expression($expression) - { - return $expression; - } - /** * {@inheritDoc} */ @@ -440,10 +405,9 @@ class postgres extends \phpbb\db\driver\driver } /** - * return sql error array - * @access private + * {@inheritDoc} */ - function _sql_error() + protected function _sql_error(): array { // pg_last_error only works when there is an established connection. // Connection errors have to be tracked by us manually. @@ -463,10 +427,9 @@ class postgres extends \phpbb\db\driver\driver } /** - * Close sql connection - * @access private - */ - function _sql_close() + * {@inheritDoc} + */ + protected function _sql_close(): bool { // Released resources are already closed, return true in this case if (!is_resource($this->db_connect_id)) @@ -477,10 +440,9 @@ class postgres extends \phpbb\db\driver\driver } /** - * Build db-specific report - * @access private + * {@inheritDoc} */ - function _sql_report($mode, $query = '') + protected function _sql_report(string $mode, string $query = ''): void { switch ($mode) { diff --git a/phpBB/phpbb/db/driver/sqlite3.php b/phpBB/phpbb/db/driver/sqlite3.php index 61b87d86b5..0be8b14104 100644 --- a/phpBB/phpbb/db/driver/sqlite3.php +++ b/phpBB/phpbb/db/driver/sqlite3.php @@ -83,27 +83,20 @@ class sqlite3 extends \phpbb\db\driver\driver } /** - * SQL Transaction - * - * @param string $status Should be one of the following strings: - * begin, commit, rollback - * @return bool Success/failure of the transaction query + * {@inheritDoc} */ - protected function _sql_transaction($status = 'begin') + protected function _sql_transaction(string $status = 'begin'): bool { switch ($status) { case 'begin': return $this->dbo->exec('BEGIN IMMEDIATE'); - break; case 'commit': return $this->dbo->exec('COMMIT'); - break; case 'rollback': return @$this->dbo->exec('ROLLBACK'); - break; } return true; @@ -188,16 +181,9 @@ class sqlite3 extends \phpbb\db\driver\driver } /** - * Build LIMIT query - * - * @param string $query The SQL query to execute - * @param int $total The number of rows to select - * @param int $offset - * @param int $cache_ttl Either 0 to avoid caching or - * the time in seconds which the result shall be kept in cache - * @return mixed Buffered, seekable result handle, false on error + * {@inheritDoc} */ - protected function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + protected function _sql_query_limit(string $query, int $total, int $offset = 0, int $cache_ttl = 0) { $this->query_result = false; @@ -263,12 +249,13 @@ class sqlite3 extends \phpbb\db\driver\driver if ($cache && !is_object($query_id) && $cache->sql_exists($query_id)) { - return $cache->sql_freeresult($query_id); + $cache->sql_freeresult($query_id); + return; } if ($query_id) { - return @$query_id->finalize(); + @$query_id->finalize(); } } @@ -315,11 +302,9 @@ class sqlite3 extends \phpbb\db\driver\driver } /** - * return sql error array - * - * @return array + * {@inheritDoc} */ - protected function _sql_error() + protected function _sql_error(): array { if (class_exists('SQLite3', false) && isset($this->dbo)) { @@ -340,24 +325,9 @@ class sqlite3 extends \phpbb\db\driver\driver } /** - * Build db-specific query data - * - * @param string $stage Available stages: FROM, WHERE - * @param mixed $data A string containing the CROSS JOIN query or an array of WHERE clauses - * - * @return string The db-specific query fragment + * {@inheritDoc} */ - protected function _sql_custom_build($stage, $data) - { - return $data; - } - - /** - * Close sql connection - * - * @return bool False if failure - */ - protected function _sql_close() + protected function _sql_close(): bool { return $this->dbo->close(); } @@ -365,12 +335,13 @@ class sqlite3 extends \phpbb\db\driver\driver /** * Build db-specific report * - * @param string $mode Available modes: display, start, stop, + * @param string $mode Available modes: display, start, stop, * add_select_row, fromcache, record_fromcache - * @param string $query The Query that should be explained - * @return mixed Either a full HTML page, boolean or null + * @param string $query The Query that should be explained + * + * @return void Either writes HTML to html_hold or outputs a full HTML page */ - protected function _sql_report($mode, $query = '') + protected function _sql_report(string $mode, string $query = ''): void { switch ($mode) { diff --git a/phpBB/phpbb/db/extractor/factory.php b/phpBB/phpbb/db/extractor/factory.php index f27aae720f..7499baba09 100644 --- a/phpBB/phpbb/db/extractor/factory.php +++ b/phpBB/phpbb/db/extractor/factory.php @@ -51,25 +51,30 @@ class factory // Return the appropriate DB extractor if ($this->db instanceof \phpbb\db\driver\mssql_base) { - return $this->container->get('dbal.extractor.extractors.mssql_extractor'); + $extractor = $this->container->get('dbal.extractor.extractors.mssql_extractor'); } else if ($this->db instanceof \phpbb\db\driver\mysql_base) { - return $this->container->get('dbal.extractor.extractors.mysql_extractor'); + $extractor = $this->container->get('dbal.extractor.extractors.mysql_extractor'); } else if ($this->db instanceof \phpbb\db\driver\oracle) { - return $this->container->get('dbal.extractor.extractors.oracle_extractor'); + $extractor = $this->container->get('dbal.extractor.extractors.oracle_extractor'); } else if ($this->db instanceof \phpbb\db\driver\postgres) { - return $this->container->get('dbal.extractor.extractors.postgres_extractor'); + $extractor = $this->container->get('dbal.extractor.extractors.postgres_extractor'); } else if ($this->db instanceof \phpbb\db\driver\sqlite3) { - return $this->container->get('dbal.extractor.extractors.sqlite3_extractor'); + $extractor = $this->container->get('dbal.extractor.extractors.sqlite3_extractor'); + } + else + { + throw new \InvalidArgumentException('Invalid database driver given'); } - throw new \InvalidArgumentException('Invalid database driver given'); + /** @var \phpbb\db\extractor\extractor_interface $extractor */ + return $extractor; } } diff --git a/phpBB/phpbb/db/extractor/mssql_extractor.php b/phpBB/phpbb/db/extractor/mssql_extractor.php index 64922c1124..1fa921bc3d 100644 --- a/phpBB/phpbb/db/extractor/mssql_extractor.php +++ b/phpBB/phpbb/db/extractor/mssql_extractor.php @@ -194,12 +194,12 @@ class mssql_extractor extends base_extractor * Extracts data from database table (for MSSQL Native driver) * * @param string $table_name name of the database table - * @return null + * @return void * @throws extractor_not_initialized_exception when calling this function before init_extractor() */ protected function write_data_mssqlnative($table_name) { - if (!$this->is_initialized) + if (!$this->is_initialized || !$this->db instanceof \phpbb\db\driver\mssqlnative) { throw new extractor_not_initialized_exception(); } diff --git a/phpBB/phpbb/db/extractor/oracle_extractor.php b/phpBB/phpbb/db/extractor/oracle_extractor.php index bc43a37b10..879e377043 100644 --- a/phpBB/phpbb/db/extractor/oracle_extractor.php +++ b/phpBB/phpbb/db/extractor/oracle_extractor.php @@ -184,12 +184,12 @@ class oracle_extractor extends base_extractor FROM $table_name"; $result = $this->db->sql_query($sql); - $i_num_fields = ocinumcols($result); + $i_num_fields = oci_num_fields($result); for ($i = 0; $i < $i_num_fields; $i++) { - $ary_type[$i] = ocicolumntype($result, $i + 1); - $ary_name[$i] = ocicolumnname($result, $i + 1); + $ary_type[$i] = oci_field_type($result, $i + 1); + $ary_name[$i] = oci_field_name($result, $i + 1); } while ($row = $this->db->sql_fetchrow($result)) diff --git a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php index 407bd39ce6..969b1e227e 100644 --- a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php +++ b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php @@ -122,6 +122,8 @@ class soft_delete_mod_convert extends container_aware_migration */ protected function get_content_visibility() { - return $this->container->get('content.visibility'); + /** @var \phpbb\content_visibility $content_visibility */ + $content_visibility = $this->container->get('content.visibility'); + return $content_visibility; } } diff --git a/phpBB/phpbb/db/migration/data/v31x/remove_duplicate_migrations.php b/phpBB/phpbb/db/migration/data/v31x/remove_duplicate_migrations.php index 7f8acc0cd5..17f4152f05 100644 --- a/phpBB/phpbb/db/migration/data/v31x/remove_duplicate_migrations.php +++ b/phpBB/phpbb/db/migration/data/v31x/remove_duplicate_migrations.php @@ -49,17 +49,21 @@ class remove_duplicate_migrations extends \phpbb\db\migration\migration $this->db->sql_freeresult($result); + /** + * @var string $name + * @var array $migration + */ foreach ($migration_state as $name => $migration) { $prepended_name = ($name[0] == '\\' ? '' : '\\') . $name; $prefixless_name = $name[0] == '\\' ? substr($name, 1) : $name; - if ($prepended_name != $name && isset($migration_state[$prepended_name]) && $migration_state[$prepended_name]['migration_depends_on'] == $migration_state[$name]['migration_depends_on']) + if ($prepended_name != $name && isset($migration_state[$prepended_name]) && $migration_state[$prepended_name]['migration_depends_on'] == $migration['migration_depends_on']) { $duplicate_migrations[] = $name; unset($migration_state[$prepended_name]); } - else if ($prefixless_name != $name && isset($migration_state[$prefixless_name]) && $migration_state[$prefixless_name]['migration_depends_on'] == $migration_state[$name]['migration_depends_on']) + else if ($prefixless_name != $name && isset($migration_state[$prefixless_name]) && $migration_state[$prefixless_name]['migration_depends_on'] == $migration['migration_depends_on']) { $duplicate_migrations[] = $prefixless_name; unset($migration_state[$prefixless_name]); diff --git a/phpBB/phpbb/db/migration/tool/config.php b/phpBB/phpbb/db/migration/tool/config.php index a351c4858e..b5404bdba5 100644 --- a/phpBB/phpbb/db/migration/tool/config.php +++ b/phpBB/phpbb/db/migration/tool/config.php @@ -47,7 +47,7 @@ class config implements \phpbb\db\migration\tool\tool_interface * @param mixed $config_value The value of the config setting * @param bool $is_dynamic True if it is dynamic (changes very often) * and should not be stored in the cache, false if not. - * @return null + * @return void */ public function add($config_name, $config_value, $is_dynamic = false) { @@ -65,7 +65,7 @@ class config implements \phpbb\db\migration\tool\tool_interface * @param string $config_name The name of the config setting you would * like to update * @param mixed $config_value The value of the config setting - * @return null + * @return void * @throws \phpbb\db\migration\exception */ public function update($config_name, $config_value) @@ -87,7 +87,7 @@ class config implements \phpbb\db\migration\tool\tool_interface * @param string $config_name The name of the config setting you would * like to update * @param mixed $config_value The value of the config setting - * @return null + * @return void * @throws \phpbb\db\migration\exception */ public function update_if_equals($compare, $config_name, $config_value) @@ -105,7 +105,7 @@ class config implements \phpbb\db\migration\tool\tool_interface * * @param string $config_name The name of the config setting you would * like to remove - * @return null + * @return void */ public function remove($config_name) { diff --git a/phpBB/phpbb/db/migration/tool/config_text.php b/phpBB/phpbb/db/migration/tool/config_text.php index 5fe9a25b70..eb3d5b3385 100644 --- a/phpBB/phpbb/db/migration/tool/config_text.php +++ b/phpBB/phpbb/db/migration/tool/config_text.php @@ -45,7 +45,7 @@ class config_text implements \phpbb\db\migration\tool\tool_interface * @param string $config_name The name of the config_text setting * you would like to add * @param mixed $config_value The value of the config_text setting - * @return null + * @return void */ public function add($config_name, $config_value) { @@ -81,7 +81,7 @@ class config_text implements \phpbb\db\migration\tool\tool_interface * * @param string $config_name The name of the config_text setting you would * like to remove - * @return null + * @return void */ public function remove($config_name) { diff --git a/phpBB/phpbb/db/migration/tool/module.php b/phpBB/phpbb/db/migration/tool/module.php index f33172a708..7c8f80444e 100644 --- a/phpBB/phpbb/db/migration/tool/module.php +++ b/phpBB/phpbb/db/migration/tool/module.php @@ -162,7 +162,7 @@ class module implements \phpbb\db\migration\tool\tool_interface * Optionally you may not send 'modes' and it will insert all of the * modules in that info file. * path, specify that here - * @return null + * @return void * @throws \phpbb\db\migration\exception */ public function add($class, $parent = 0, $data = array()) diff --git a/phpBB/phpbb/db/migration/tool/permission.php b/phpBB/phpbb/db/migration/tool/permission.php index 8628c38f5b..91838a4a47 100644 --- a/phpBB/phpbb/db/migration/tool/permission.php +++ b/phpBB/phpbb/db/migration/tool/permission.php @@ -21,7 +21,7 @@ class permission implements \phpbb\db\migration\tool\tool_interface /** @var \phpbb\auth\auth */ protected $auth; - /** @var \includes\acp\auth\auth_admin */ + /** @var \auth_admin */ protected $auth_admin; /** @var \phpbb\cache\service */ @@ -115,7 +115,7 @@ class permission implements \phpbb\db\migration\tool\tool_interface * @param bool $global True for checking a global permission setting, * False for a local permission setting * @param int|false $copy_from If set, contains the id of the permission from which to copy the new one. - * @return null + * @return void */ public function add($auth_option, $global = true, $copy_from = false) { @@ -189,7 +189,7 @@ class permission implements \phpbb\db\migration\tool\tool_interface * @param string $auth_option The name of the permission (auth) option * @param bool $global True for checking a global permission setting, * False for a local permission setting - * @return null + * @return void */ public function remove($auth_option, $global = true) { @@ -266,7 +266,7 @@ class permission implements \phpbb\db\migration\tool\tool_interface * @param string $role_type The type (u_, m_, a_) * @param string $role_description Description of the new role * - * @return null + * @return int|null Inserted SQL id or false if role already exists */ public function role_add($role_name, $role_type, $role_description = '') { @@ -292,7 +292,7 @@ class permission implements \phpbb\db\migration\tool\tool_interface $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); - return $this->db->sql_nextid(); + return (int) $this->db->sql_nextid(); } /** @@ -300,7 +300,7 @@ class permission implements \phpbb\db\migration\tool\tool_interface * * @param string $old_role_name The old role name * @param string $new_role_name The new role name - * @return null + * @return void * @throws \phpbb\db\migration\exception */ public function role_update($old_role_name, $new_role_name) @@ -320,7 +320,7 @@ class permission implements \phpbb\db\migration\tool\tool_interface * Remove a permission role * * @param string $role_name The role name to remove - * @return null + * @return void */ public function role_remove($role_name) { @@ -704,9 +704,6 @@ class permission implements \phpbb\db\migration\tool\tool_interface break; } - if ($call) - { - return call_user_func_array(array(&$this, $call), $arguments); - } + return $call ? call_user_func_array(array(&$this, $call), $arguments) : null; } } diff --git a/phpBB/phpbb/db/migration/tool/tool_interface.php b/phpBB/phpbb/db/migration/tool/tool_interface.php index 07cd2435e4..1b66807665 100644 --- a/phpBB/phpbb/db/migration/tool/tool_interface.php +++ b/phpBB/phpbb/db/migration/tool/tool_interface.php @@ -31,7 +31,7 @@ interface tool_interface * First argument is the original call to the class (e.g. add, remove) * After the first argument, send the original arguments to the function in the original call * - * @return null + * @return mixed|null Return of function call or null if no valid function call found */ public function reverse(); } diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index ef97438cf9..bdb85a7996 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -90,7 +90,7 @@ class migrator * * 'effectively_installed' set and set to true if the migration was effectively_installed * - * @var array|bool + * @var array|false */ protected $last_run_migration = false; @@ -192,7 +192,7 @@ class migrator * The array contains 'name', 'class' and 'state'. 'effectively_installed' is set * and set to true if the last migration was effectively_installed. * - * @return array + * @return array|false Last run migration information or false if no migration has been run yet */ public function get_last_run_migration() { @@ -296,7 +296,7 @@ class migrator /** * Effectively runs a single update step from the next migration to be applied. * - * @return null + * @return void */ protected function update_do() { @@ -517,7 +517,7 @@ class migrator * Effectively runs a single revert step from the last migration installed * * @param string $migration String migration name to revert (including any that depend on this migration) - * @return null + * @return void */ protected function revert_do($migration) { @@ -651,7 +651,7 @@ class migrator * @param array $steps The steps to run * @param bool|string $state Current state of the migration * @param bool $revert true to revert a data step - * @return bool|string migration state. True if completed, serialized array if not finished + * @return bool|array{result: mixed, step: int} migration state. True if completed, serialized array if not finished * @throws \phpbb\db\migration\exception */ protected function process_data_step($steps, $state, $revert = false) @@ -744,7 +744,8 @@ class migrator * @param array $step Data step from migration * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @param bool $reverse False to install, True to attempt uninstallation by reversing the call - * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters + * @return array|false Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters; + * false if no callable can be created from data setp * @throws \phpbb\db\migration\exception */ protected function get_callable_from_step(array $step, $last_result = 0, $reverse = false) diff --git a/phpBB/phpbb/db/tools/doctrine.php b/phpBB/phpbb/db/tools/doctrine.php index 0e5e8ffbf4..e956bcff4b 100644 --- a/phpBB/phpbb/db/tools/doctrine.php +++ b/phpBB/phpbb/db/tools/doctrine.php @@ -462,7 +462,8 @@ class doctrine implements tools_interface } catch (Exception $e) { - return $e->getMessage(); + // @todo: check if it makes sense to properly handle the exception + return false; } } From a8b878349a06638d33004086ce9e0c673e3f2a59 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 14:29:13 +0100 Subject: [PATCH 23/42] [ticket/16955] Remove shell option as this has been removed in Symfony 3.0 PHPBB3-16955 --- phpBB/phpbb/console/application.php | 59 ----------------------------- 1 file changed, 59 deletions(-) diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 830ed1b2c1..6726904e8f 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -21,11 +21,6 @@ use Symfony\Component\Console\Output\OutputInterface; class application extends \Symfony\Component\Console\Application { - /** - * @var bool Indicates whether or not we are in a shell - */ - protected $in_shell = false; - /** * @var \phpbb\config\config Config object */ @@ -62,41 +57,6 @@ class application extends \Symfony\Component\Console\Application return $input_definition; } - /** - * Gets the help message. - * - * It's a hack of the default help message to display the --shell - * option only for the application and not for all the commands. - * - * @return string A help message. - */ - public function getHelp() - { - // If we are already in a shell - // we do not want to have the --shell option available - if ($this->in_shell) - { - return parent::getHelp(); - } - - try - { - $definition = $this->getDefinition(); - $definition->addOption(new InputOption( - '--shell', - '-s', - InputOption::VALUE_NONE, - $this->language->lang('CLI_DESCRIPTION_OPTION_SHELL') - )); - } - catch (\LogicException $e) - { - // Do nothing - } - - return parent::getHelp(); - } - /** * Register a set of commands from the container * @@ -118,25 +78,6 @@ class application extends \Symfony\Component\Console\Application } } - /** - * {@inheritdoc} - */ - public function doRun(InputInterface $input, OutputInterface $output) - { - // Run a shell if the --shell (or -s) option is set and if no command name is specified - // Also, we do not want to have the --shell option available if we are already in a shell - if (!$this->in_shell && $this->getCommandName($input) === null && $input->hasParameterOption(array('--shell', '-s'))) - { - $shell = new Shell($this); - $this->in_shell = true; - $shell->run(); - - return 0; - } - - return parent::doRun($input, $output); - } - /** * Register global options * From b855b8a5a509b5589a2fdbb9594a2e8158e2e573 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 14:31:23 +0100 Subject: [PATCH 24/42] [ticket/16955] Clean up cron and console classes PHPBB3-16955 --- phpBB/phpbb/console/command/fixup/update_hashes.php | 2 +- phpBB/phpbb/cron/manager.php | 2 +- phpBB/phpbb/cron/task/core/prune_shadow_topics.php | 5 ++--- phpBB/phpbb/cron/task/core/update_hashes.php | 2 +- phpBB/phpbb/cron/task/wrapper.php | 4 ++-- phpBB/phpbb/passwords/manager.php | 4 ++-- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/phpBB/phpbb/console/command/fixup/update_hashes.php b/phpBB/phpbb/console/command/fixup/update_hashes.php index d12d0e755d..05bef48c92 100644 --- a/phpBB/phpbb/console/command/fixup/update_hashes.php +++ b/phpBB/phpbb/console/command/fixup/update_hashes.php @@ -101,7 +101,7 @@ class update_hashes extends \phpbb\console\command\command while ($row = $this->db->sql_fetchrow($result)) { $old_hash = preg_replace('/^\$CP\$/', '', $row['user_password']); - $new_hash = $this->passwords_manager->hash($old_hash, array($this->default_type)); + $new_hash = $this->passwords_manager->hash($old_hash, [$this->default_type]); $sql = 'UPDATE ' . USERS_TABLE . " SET user_password = '" . $this->db->sql_escape($new_hash) . "' diff --git a/phpBB/phpbb/cron/manager.php b/phpBB/phpbb/cron/manager.php index f412ab85eb..8a64acc4a5 100644 --- a/phpBB/phpbb/cron/manager.php +++ b/phpBB/phpbb/cron/manager.php @@ -164,7 +164,7 @@ class manager * Web runner uses this method to resolve names to tasks. * * @param string $name Name of the task to look up. - * @return wrapper A wrapped task corresponding to the given name, or null. + * @return wrapper|null A wrapped task corresponding to the given name, or null. */ public function find_task($name) { diff --git a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php index 0ab59f9ed5..81873a673b 100644 --- a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php +++ b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php @@ -166,7 +166,8 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t * @param int $prune_flags Prune flags * @param int $prune_days Prune date in days * @param int $prune_freq Prune frequency - * @return null + * + * @return void */ protected function auto_prune_shadow_topics($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_freq) { @@ -194,7 +195,5 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t $this->log->add('admin', $user_id, $user_ip, 'LOG_PRUNE_SHADOW', false, array($row['forum_name'])); } - - return; } } diff --git a/phpBB/phpbb/cron/task/core/update_hashes.php b/phpBB/phpbb/cron/task/core/update_hashes.php index 3348a4576e..61ed0d0501 100644 --- a/phpBB/phpbb/cron/task/core/update_hashes.php +++ b/phpBB/phpbb/cron/task/core/update_hashes.php @@ -107,7 +107,7 @@ class update_hashes extends \phpbb\cron\task\base while ($row = $this->db->sql_fetchrow($result)) { $old_hash = preg_replace('/^\$CP\$/', '', $row['user_password']); - $new_hash = $this->passwords_manager->hash($old_hash, array($this->default_type)); + $new_hash = $this->passwords_manager->hash($old_hash, [$this->default_type]); // Increase number so we know that users were selected from the database $affected_rows++; diff --git a/phpBB/phpbb/cron/task/wrapper.php b/phpBB/phpbb/cron/task/wrapper.php index 52fd5e4368..1eb5db6067 100644 --- a/phpBB/phpbb/cron/task/wrapper.php +++ b/phpBB/phpbb/cron/task/wrapper.php @@ -91,7 +91,7 @@ class wrapper { $params = []; $params['cron_type'] = $this->get_name(); - if ($this->is_parametrized()) + if ($this->task instanceof parametrized) { $params = array_merge($params, $this->task->get_parameters()); } @@ -113,7 +113,7 @@ class wrapper $this->template->assign_var('CRON_TASK_URL', $this->get_url()); - return $this->template->assign_display('cron_html_tag'); + return (string) $this->template->assign_display('cron_html_tag'); } /** diff --git a/phpBB/phpbb/passwords/manager.php b/phpBB/phpbb/passwords/manager.php index 33d7196d22..aa79150aee 100644 --- a/phpBB/phpbb/passwords/manager.php +++ b/phpBB/phpbb/passwords/manager.php @@ -206,8 +206,8 @@ class manager * Hash supplied password * * @param string $password Password that should be hashed - * @param string $type Hash type. Will default to standard hash type if - * none is supplied + * @param string|array $type Hash type. Will default to standard hash type if + * none is supplied, array for combined hashing * @return string|bool Password hash of supplied password or false if * if something went wrong during hashing */ From 83cb41e72a7352e22e2d00b6f3f99332000643e7 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 16:12:53 +0100 Subject: [PATCH 25/42] [ticket/16955] Add stubs for cache classes and clean up PHPBB3-16955 --- build/psalm/stubs/apcu/apcu.php | 24 +++++++++++++++ build/psalm/stubs/memcached/memcached.php | 20 +++++++++++++ build/psalm/stubs/redis/redis.php | 21 +++++++++++++ build/psalm/stubs/sqlite3/sqlite3.php | 1 + phpBB/phpbb/cache/driver/apcu.php | 28 +++++------------ phpBB/phpbb/cache/driver/base.php | 11 ++++++- phpBB/phpbb/cache/driver/driver_interface.php | 2 +- phpBB/phpbb/cache/driver/dummy.php | 8 +++++ phpBB/phpbb/cache/driver/file.php | 12 +++----- phpBB/phpbb/cache/driver/memcached.php | 28 +++++------------ phpBB/phpbb/cache/driver/memory.php | 24 +++++++++++++-- phpBB/phpbb/cache/driver/redis.php | 30 +++++-------------- phpBB/phpbb/cache/driver/wincache.php | 30 +++++-------------- psalm.xml | 3 ++ tests/cache/cache_memory.php | 30 +++++-------------- 15 files changed, 153 insertions(+), 119 deletions(-) create mode 100644 build/psalm/stubs/apcu/apcu.php create mode 100644 build/psalm/stubs/memcached/memcached.php create mode 100644 build/psalm/stubs/redis/redis.php diff --git a/build/psalm/stubs/apcu/apcu.php b/build/psalm/stubs/apcu/apcu.php new file mode 100644 index 0000000000..55d1463e4d --- /dev/null +++ b/build/psalm/stubs/apcu/apcu.php @@ -0,0 +1,24 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +/** @link https://www.php.net/manual/en/memcached.constants.php */ +class Memcached +{ + public const OPT_COMPRESSION = -1001; + + public const OPT_BINARY_PROTOCOL = 18; +} diff --git a/build/psalm/stubs/redis/redis.php b/build/psalm/stubs/redis/redis.php new file mode 100644 index 0000000000..b18c224bd0 --- /dev/null +++ b/build/psalm/stubs/redis/redis.php @@ -0,0 +1,21 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +/** @link https://phpredis.github.io/phpredis/Redis.html */ +class Redis +{ + public const OPT_PREFIX = 2; + + public const SERIALIZER_PHP = 1; + +} diff --git a/build/psalm/stubs/sqlite3/sqlite3.php b/build/psalm/stubs/sqlite3/sqlite3.php index a102b39fca..5646c6623e 100644 --- a/build/psalm/stubs/sqlite3/sqlite3.php +++ b/build/psalm/stubs/sqlite3/sqlite3.php @@ -10,6 +10,7 @@ * the docs/CREDITS.txt file. * */ + class SQLite3 { public function query(string $query) {} diff --git a/phpBB/phpbb/cache/driver/apcu.php b/phpBB/phpbb/cache/driver/apcu.php index 6bcc13cf78..0160ef7eb9 100644 --- a/phpBB/phpbb/cache/driver/apcu.php +++ b/phpBB/phpbb/cache/driver/apcu.php @@ -38,39 +38,25 @@ class apcu extends \phpbb\cache\driver\memory } /** - * Fetch an item from the cache - * - * @access protected - * @param string $var Cache key - * @return mixed Cached data + * {@inheritDoc} */ - function _read($var) + protected function _read(string $var) { return apcu_fetch($this->key_prefix . $var); } /** - * Store data in the cache - * - * @access protected - * @param string $var Cache key - * @param mixed $data Data to store - * @param int $ttl Time-to-live of cached data - * @return bool True if the operation succeeded + * {@inheritDoc} */ - function _write($var, $data, $ttl = 2592000) + protected function _write(string $var, $data, int $ttl = 2592000): bool { return apcu_store($this->key_prefix . $var, $data, $ttl); } /** - * Remove an item from the cache - * - * @access protected - * @param string $var Cache key - * @return bool True if the operation succeeded - */ - function _delete($var) + * {@inheritDoc} + */ + protected function _delete(string $var): bool { return apcu_delete($this->key_prefix . $var); } diff --git a/phpBB/phpbb/cache/driver/base.php b/phpBB/phpbb/cache/driver/base.php index 3eca521148..29352e84b3 100644 --- a/phpBB/phpbb/cache/driver/base.php +++ b/phpBB/phpbb/cache/driver/base.php @@ -199,7 +199,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface * * @param string $dir Directory to remove * - * @return null + * @return void */ protected function remove_dir($dir) { @@ -231,4 +231,13 @@ abstract class base implements \phpbb\cache\driver\driver_interface @rmdir($dir); } + + /** + * Fetch an item from the cache + * + * @param string $var Cache key + * + * @return mixed Cached data + */ + abstract protected function _read(string $var); } diff --git a/phpBB/phpbb/cache/driver/driver_interface.php b/phpBB/phpbb/cache/driver/driver_interface.php index 9ac9ca0c59..61ce39d496 100644 --- a/phpBB/phpbb/cache/driver/driver_interface.php +++ b/phpBB/phpbb/cache/driver/driver_interface.php @@ -95,7 +95,7 @@ interface driver_interface * * @param string $query SQL query * - * @return int|bool Query ID (integer) if cache contains a rowset + * @return string|false Query ID (md5 of query) if cache contains a rowset * for the specified query. * False otherwise. */ diff --git a/phpBB/phpbb/cache/driver/dummy.php b/phpBB/phpbb/cache/driver/dummy.php index 1f74f6dd77..df5896d4e9 100644 --- a/phpBB/phpbb/cache/driver/dummy.php +++ b/phpBB/phpbb/cache/driver/dummy.php @@ -95,6 +95,14 @@ class dummy extends \phpbb\cache\driver\base return false; } + /** + * {@inheritDoc} + */ + protected function _read(string $var) + { + return false; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php index 36150d0589..2dc9f350c2 100644 --- a/phpBB/phpbb/cache/driver/file.php +++ b/phpBB/phpbb/cache/driver/file.php @@ -331,17 +331,13 @@ class file extends \phpbb\cache\driver\base } /** - * Read cached data from a specified file - * - * @access private - * @param string $filename Filename to write - * @return mixed False if an error was encountered, otherwise the data type of the cached data - */ - function _read($filename) + * {@inheritDoc} + */ + protected function _read(string $var) { global $phpEx; - $filename = $this->clean_varname($filename); + $filename = $this->clean_varname($var); $file = "{$this->cache_dir}$filename.$phpEx"; $type = substr($filename, 0, strpos($filename, '_')); diff --git a/phpBB/phpbb/cache/driver/memcached.php b/phpBB/phpbb/cache/driver/memcached.php index fbb587a369..ca4922b73f 100644 --- a/phpBB/phpbb/cache/driver/memcached.php +++ b/phpBB/phpbb/cache/driver/memcached.php @@ -37,7 +37,7 @@ if (!defined('PHPBB_ACM_MEMCACHED')) /** * ACM for Memcached */ -class memcached extends \phpbb\cache\driver\memory +class memcached extends memory { /** @var string Extension to use */ protected $extension = 'memcached'; @@ -107,26 +107,17 @@ class memcached extends \phpbb\cache\driver\memory } /** - * Fetch an item from the cache - * - * @param string $var Cache key - * - * @return mixed Cached data - */ - protected function _read($var) + * {@inheritDoc} + */ + protected function _read(string $var) { return $this->memcached->get($this->key_prefix . $var); } /** - * Store data in the cache - * - * @param string $var Cache key - * @param mixed $data Data to store - * @param int $ttl Time-to-live of cached data - * @return bool True if the operation succeeded + * {@inheritDoc} */ - protected function _write($var, $data, $ttl = 2592000) + protected function _write(string $var, $data, int $ttl = 2592000): bool { if (!$this->memcached->replace($this->key_prefix . $var, $data, $ttl)) { @@ -136,12 +127,9 @@ class memcached extends \phpbb\cache\driver\memory } /** - * Remove an item from the cache - * - * @param string $var Cache key - * @return bool True if the operation succeeded + * {@inheritDoc} */ - protected function _delete($var) + protected function _delete(string $var): bool { return $this->memcached->delete($this->key_prefix . $var); } diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php index 956936bf6f..0a4ea304ad 100644 --- a/phpBB/phpbb/cache/driver/memory.php +++ b/phpBB/phpbb/cache/driver/memory.php @@ -270,13 +270,33 @@ abstract class memory extends \phpbb\cache\driver\base /** * Check if a cache var exists * - * @access protected * @param string $var Cache key + * * @return bool True if it exists, otherwise false */ - function _isset($var) + protected function _isset(string $var): bool { // Most caches don't need to check return true; } + + /** + * Remove an item from the cache + * + * @param string $var Cache key + * + * @return bool True if the operation succeeded + */ + abstract protected function _delete(string $var): bool; + + /** + * Store data in the cache + * + * @param string $var Cache key + * @param mixed $data Data to store + * @param int $ttl Time-to-live of cached data + * + * @return bool True if the operation succeeded + */ + abstract protected function _write(string $var, $data, int $ttl = 2592000): bool; } diff --git a/phpBB/phpbb/cache/driver/redis.php b/phpBB/phpbb/cache/driver/redis.php index eaeb529918..c0b47dae46 100644 --- a/phpBB/phpbb/cache/driver/redis.php +++ b/phpBB/phpbb/cache/driver/redis.php @@ -115,27 +115,17 @@ class redis extends \phpbb\cache\driver\memory } /** - * Fetch an item from the cache - * - * @access protected - * @param string $var Cache key - * @return mixed Cached data - */ - function _read($var) + * {@inheritDoc} + */ + protected function _read(string $var) { return $this->redis->get($var); } /** - * Store data in the cache - * - * @access protected - * @param string $var Cache key - * @param mixed $data Data to store - * @param int $ttl Time-to-live of cached data - * @return bool True if the operation succeeded + * {@inheritDoc} */ - function _write($var, $data, $ttl = 2592000) + protected function _write(string $var, $data, int $ttl = 2592000): bool { if ($ttl == 0) { @@ -145,13 +135,9 @@ class redis extends \phpbb\cache\driver\memory } /** - * Remove an item from the cache - * - * @access protected - * @param string $var Cache key - * @return bool True if the operation succeeded - */ - function _delete($var) + * {@inheritDoc} + */ + protected function _delete(string $var): bool { if ($this->redis->delete($var) > 0) { diff --git a/phpBB/phpbb/cache/driver/wincache.php b/phpBB/phpbb/cache/driver/wincache.php index 632b534362..367de2478b 100644 --- a/phpBB/phpbb/cache/driver/wincache.php +++ b/phpBB/phpbb/cache/driver/wincache.php @@ -31,13 +31,9 @@ class wincache extends \phpbb\cache\driver\memory } /** - * Fetch an item from the cache - * - * @access protected - * @param string $var Cache key - * @return mixed Cached data - */ - function _read($var) + * {@inheritDoc} + */ + protected function _read(string $var) { $success = false; $result = wincache_ucache_get($this->key_prefix . $var, $success); @@ -46,27 +42,17 @@ class wincache extends \phpbb\cache\driver\memory } /** - * Store data in the cache - * - * @access protected - * @param string $var Cache key - * @param mixed $data Data to store - * @param int $ttl Time-to-live of cached data - * @return bool True if the operation succeeded + * {@inheritDoc} */ - function _write($var, $data, $ttl = 2592000) + protected function _write(string $var, $data, int $ttl = 2592000): bool { return wincache_ucache_set($this->key_prefix . $var, $data, $ttl); } /** - * Remove an item from the cache - * - * @access protected - * @param string $var Cache key - * @return bool True if the operation succeeded - */ - function _delete($var) + * {@inheritDoc} + */ + protected function _delete(string $var): bool { return wincache_ucache_delete($this->key_prefix . $var); } diff --git a/psalm.xml b/psalm.xml index 0fbf33cdef..cb434cfaf8 100644 --- a/psalm.xml +++ b/psalm.xml @@ -22,8 +22,11 @@ + + + diff --git a/tests/cache/cache_memory.php b/tests/cache/cache_memory.php index 1f7b31a86b..9d94c080f2 100644 --- a/tests/cache/cache_memory.php +++ b/tests/cache/cache_memory.php @@ -23,40 +23,26 @@ class phpbb_cache_memory extends \phpbb\cache\driver\memory } /** - * Fetch an item from the cache - * - * @access protected - * @param string $var Cache key - * @return mixed Cached data - */ - function _read($var) + * {@inheritDoc} + */ + protected function _read(string $var) { return $this->data[$var] ?? false; } /** - * Store data in the cache - * - * @access protected - * @param string $var Cache key - * @param mixed $data Data to store - * @param int $ttl Time-to-live of cached data - * @return bool True if the operation succeeded + * {@inheritDoc} */ - function _write($var, $data, $ttl = 2592000) + protected function _write(string $var, $data, int $ttl = 2592000): bool { $this->data[$var] = $data; return true; } /** - * Remove an item from the cache - * - * @access protected - * @param string $var Cache key - * @return bool True if the operation succeeded - */ - function _delete($var) + * {@inheritDoc} + */ + protected function _delete(string $var): bool { unset($this->data[$var]); return true; From 35228ffd62974e4ea59f4c9c35712bb65bc7a4d4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 16:13:56 +0100 Subject: [PATCH 26/42] [ticket/16955] Clean up captcha classes PHPBB3-16955 --- build/psalm_bootstrap.php | 1 + phpBB/includes/acp/acp_captcha.php | 8 ++++++-- phpBB/phpbb/captcha/factory.php | 2 +- phpBB/phpbb/captcha/gd.php | 2 ++ phpBB/phpbb/captcha/gd_wave.php | 8 ++++---- phpBB/phpbb/captcha/plugins/qa.php | 13 ++++++++----- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/build/psalm_bootstrap.php b/build/psalm_bootstrap.php index cea4bc64be..03afd6da3d 100644 --- a/build/psalm_bootstrap.php +++ b/build/psalm_bootstrap.php @@ -49,6 +49,7 @@ $phpbb_class_loader->register(); // Include files that require class loader to be initialized require_once $phpbb_root_path . 'includes/acp/auth.' . $phpEx; +require_once $phpbb_root_path . 'includes/acp/acp_captcha.' . $phpEx; class phpbb_cache_container extends \Symfony\Component\DependencyInjection\Container { diff --git a/phpBB/includes/acp/acp_captcha.php b/phpBB/includes/acp/acp_captcha.php index b49c5ca0d3..ff9f515d32 100644 --- a/phpBB/includes/acp/acp_captcha.php +++ b/phpBB/includes/acp/acp_captcha.php @@ -23,6 +23,12 @@ class acp_captcha { var $u_action; + /** @var string Template name */ + public $tpl_name = 'acp_captcha'; + + /** @var string Page title language variable */ + public $page_title = 'ACP_VC_SETTINGS'; + function main($id, $mode) { global $user, $template, $phpbb_log, $request; @@ -85,8 +91,6 @@ class acp_captcha ), ); - $this->tpl_name = 'acp_captcha'; - $this->page_title = 'ACP_VC_SETTINGS'; $form_key = 'acp_captcha'; add_form_key($form_key); diff --git a/phpBB/phpbb/captcha/factory.php b/phpBB/phpbb/captcha/factory.php index dd44aca8bb..2e75ce8667 100644 --- a/phpBB/phpbb/captcha/factory.php +++ b/phpBB/phpbb/captcha/factory.php @@ -41,7 +41,7 @@ class factory * Return a new instance of a given plugin * * @param $name - * @return object + * @return object|null */ public function get_instance($name) { diff --git a/phpBB/phpbb/captcha/gd.php b/phpBB/phpbb/captcha/gd.php index 7f4d26ff00..308bc73e0b 100644 --- a/phpBB/phpbb/captcha/gd.php +++ b/phpBB/phpbb/captcha/gd.php @@ -1653,6 +1653,8 @@ class gd ), ), ); + + /** @var 1|2|3 $config['captcha_gd_fonts'] */ return array( 'width' => 9, 'height' => 15, diff --git a/phpBB/phpbb/captcha/gd_wave.php b/phpBB/phpbb/captcha/gd_wave.php index 4f64e95a1d..e0801e7c50 100644 --- a/phpBB/phpbb/captcha/gd_wave.php +++ b/phpBB/phpbb/captcha/gd_wave.php @@ -205,7 +205,7 @@ class gd_wave $x_index_old = intval(($x - 1) / $subdivision_factor); $x_index_new = intval($x / $subdivision_factor); - if (!empty($plane[$y_index_new][$x_index_new])) + if ($plane[$y_index_new][$x_index_new]) { $img_pos_cur[1] += $this->wave_height($x, $y, $subdivision_factor, 1) - 30 - $cur_height; $color = $colors[20]; @@ -213,10 +213,10 @@ class gd_wave $img_pos_cur[1] = min($img_pos_cur[1], $img_y - 1); $img_buffer[$buffer_cur][$x] = $img_pos_cur; - // Smooth the edges as much as possible by having not more than one low<->high traingle per square + // Smooth the edges as much as possible by having not more than one low<->high triangle per square // Otherwise, just - $diag_down = (empty($plane[$y_index_old][$x_index_old]) == empty($plane[$y_index_new][$x_index_new])); - $diag_up = (empty($plane[$y_index_old][$x_index_new]) == empty($plane[$y_index_new][$x_index_old])); + $diag_down = !$plane[$y_index_old][$x_index_old] && !$plane[$y_index_new][$x_index_new]; + $diag_up = !$plane[$y_index_old][$x_index_new] && !$plane[$y_index_new][$x_index_old]; // natural switching $mode = ($x + $y) & 1; diff --git a/phpBB/phpbb/captcha/plugins/qa.php b/phpBB/phpbb/captcha/plugins/qa.php index f709c95353..811421a63c 100644 --- a/phpBB/phpbb/captcha/plugins/qa.php +++ b/phpBB/phpbb/captcha/plugins/qa.php @@ -39,6 +39,9 @@ class qa */ protected $service_name; + /** @var int Question ID */ + protected $question = -1; + /** * Constructor * @@ -450,7 +453,7 @@ class qa 'session_id' => (string) $user->session_id, 'lang_iso' => (string) $this->question_lang, 'confirm_type' => (int) $this->type, - 'question_id' => (int) $this->question, + 'question_id' => $this->question, )); $db->sql_query($sql); @@ -473,7 +476,7 @@ class qa $this->solved = 0; $sql = 'UPDATE ' . $this->table_qa_confirm . ' - SET question_id = ' . (int) $this->question . " + SET question_id = ' . $this->question . " WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "' AND session_id = '" . $db->sql_escape($user->session_id) . "'"; $db->sql_query($sql); @@ -493,7 +496,7 @@ class qa $this->solved = 0; $sql = 'UPDATE ' . $this->table_qa_confirm . ' - SET question_id = ' . (int) $this->question . ", + SET question_id = ' . $this->question . ", attempts = attempts + 1 WHERE confirm_id = '" . $db->sql_escape($this->confirm_id) . "' AND session_id = '" . $db->sql_escape($user->session_id) . "'"; @@ -553,7 +556,7 @@ class qa if ($row) { - $this->question = $row['question_id']; + $this->question = (int) $row['question_id']; $this->attempts = $row['attempts']; $this->question_strict = $row['strict']; @@ -576,7 +579,7 @@ class qa $sql = 'SELECT answer_text FROM ' . $this->table_captcha_answers . ' - WHERE question_id = ' . (int) $this->question; + WHERE question_id = ' . $this->question; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) From 2aed7ff4e3849c5fc9b23f8f437c897953ed3732 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 16:15:46 +0100 Subject: [PATCH 27/42] [ticket/16955] Clean up composer classes and fix typos in exceptions PHPBB3-16955 --- .../managed_with_clean_error_exception.php | 2 +- .../managed_with_enable_error_exception.php | 2 +- .../managed_with_error_exception.php | 3 +- phpBB/phpbb/composer/extension_manager.php | 44 ++++++++++++------- phpBB/phpbb/composer/installer.php | 4 +- phpBB/phpbb/composer/manager_interface.php | 4 +- 6 files changed, 36 insertions(+), 23 deletions(-) diff --git a/phpBB/phpbb/composer/exception/managed_with_clean_error_exception.php b/phpBB/phpbb/composer/exception/managed_with_clean_error_exception.php index 22addce1b7..f7f6d163db 100644 --- a/phpBB/phpbb/composer/exception/managed_with_clean_error_exception.php +++ b/phpBB/phpbb/composer/exception/managed_with_clean_error_exception.php @@ -29,7 +29,7 @@ class managed_with_clean_error_exception extends managed_with_error_exception */ public function __construct($prefix, $message = '', array $parameters = [], \Exception $previous = null, $code = 0) { - parent::__construct($prefix . $message, $parameters, $previous, $code); + parent::__construct($prefix, $message, $parameters, $previous, $code); } } diff --git a/phpBB/phpbb/composer/exception/managed_with_enable_error_exception.php b/phpBB/phpbb/composer/exception/managed_with_enable_error_exception.php index f9b3ce571b..eace036aed 100644 --- a/phpBB/phpbb/composer/exception/managed_with_enable_error_exception.php +++ b/phpBB/phpbb/composer/exception/managed_with_enable_error_exception.php @@ -29,7 +29,7 @@ class managed_with_enable_error_exception extends managed_with_error_exception */ public function __construct($prefix, $message = '', array $parameters = [], \Exception $previous = null, $code = 0) { - parent::__construct($prefix . $message, $parameters, $previous, $code); + parent::__construct($prefix, $message, $parameters, $previous, $code); } } diff --git a/phpBB/phpbb/composer/exception/managed_with_error_exception.php b/phpBB/phpbb/composer/exception/managed_with_error_exception.php index 2ea4600cf6..0ebb1e1adf 100644 --- a/phpBB/phpbb/composer/exception/managed_with_error_exception.php +++ b/phpBB/phpbb/composer/exception/managed_with_error_exception.php @@ -29,7 +29,6 @@ class managed_with_error_exception extends runtime_exception */ public function __construct($prefix, $message = '', array $parameters = [], \Exception $previous = null, $code = 0) { - parent::__construct($prefix . $message, $parameters, $previous, $code); + parent::__construct($prefix, $message, $parameters, $previous, $code); } - } diff --git a/phpBB/phpbb/composer/extension_manager.php b/phpBB/phpbb/composer/extension_manager.php index f9d5ddb956..1e14a7591d 100644 --- a/phpBB/phpbb/composer/extension_manager.php +++ b/phpBB/phpbb/composer/extension_manager.php @@ -29,7 +29,7 @@ use phpbb\filesystem\filesystem; class extension_manager extends manager { /** - * @var manager + * @var ext_manager */ protected $extension_manager; @@ -102,7 +102,8 @@ class extension_manager extends manager { if ($this->enable_on_install) { - $io->writeError([['ENABLING_EXTENSIONS', [], 1]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([['ENABLING_EXTENSIONS', [], 1]]); foreach ($packages as $package => $version) { try @@ -111,11 +112,13 @@ class extension_manager extends manager } catch (\phpbb\exception\runtime_exception $e) { - $io->writeError([[$e->getMessage(), $e->get_parameters(), 4]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([[$e->getMessage(), $e->get_parameters(), 4]]); } catch (\Exception $e) { - $io->writeError([[$e->getMessage(), [], 4]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([[$e->getMessage(), [], 4]]); } } } @@ -126,7 +129,8 @@ class extension_manager extends manager */ protected function pre_update(array $packages, IOInterface $io = null) { - $io->writeError([['DISABLING_EXTENSIONS', [], 1]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([['DISABLING_EXTENSIONS', [], 1]]); $this->enabled_extensions = []; foreach ($packages as $package => $version) { @@ -140,11 +144,13 @@ class extension_manager extends manager } catch (\phpbb\exception\runtime_exception $e) { - $io->writeError([[$e->getMessage(), $e->get_parameters(), 4]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([[$e->getMessage(), $e->get_parameters(), 4]]); } catch (\Exception $e) { - $io->writeError([[$e->getMessage(), [], 4]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([[$e->getMessage(), [], 4]]); } } } @@ -154,7 +160,8 @@ class extension_manager extends manager */ protected function post_update(array $packages, IOInterface $io = null) { - $io->writeError([['ENABLING_EXTENSIONS', [], 1]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([['ENABLING_EXTENSIONS', [], 1]]); foreach ($this->enabled_extensions as $package) { try @@ -163,11 +170,13 @@ class extension_manager extends manager } catch (\phpbb\exception\runtime_exception $e) { - $io->writeError([[$e->getMessage(), $e->get_parameters(), 4]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([[$e->getMessage(), $e->get_parameters(), 4]]); } catch (\Exception $e) { - $io->writeError([[$e->getMessage(), [], 4]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([[$e->getMessage(), [], 4]]); } } } @@ -195,7 +204,8 @@ class extension_manager extends manager { if ($this->purge_on_remove) { - $io->writeError([['DISABLING_EXTENSIONS', [], 1]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([['DISABLING_EXTENSIONS', [], 1]]); } foreach ($packages as $package => $version) @@ -216,11 +226,13 @@ class extension_manager extends manager } catch (\phpbb\exception\runtime_exception $e) { - $io->writeError([[$e->getMessage(), $e->get_parameters(), 4]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([[$e->getMessage(), $e->get_parameters(), 4]]); } catch (\Exception $e) { - $io->writeError([[$e->getMessage(), [], 4]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([[$e->getMessage(), [], 4]]); } } } @@ -244,7 +256,8 @@ class extension_manager extends manager if ($this->extension_manager->is_enabled($package)) { $enabled = true; - $io->writeError([['DISABLING_EXTENSIONS', [], 1]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([['DISABLING_EXTENSIONS', [], 1]]); $this->extension_manager->disable($package); } @@ -279,7 +292,8 @@ class extension_manager extends manager { try { - $io->writeError([['ENABLING_EXTENSIONS', [], 1]], true); + /** @psalm-suppress InvalidArgument */ + $io->writeError([['ENABLING_EXTENSIONS', [], 1]]); $this->extension_manager->enable($package); } catch (\Exception $e) diff --git a/phpBB/phpbb/composer/installer.php b/phpBB/phpbb/composer/installer.php index 330540378d..354c7ead28 100644 --- a/phpBB/phpbb/composer/installer.php +++ b/phpBB/phpbb/composer/installer.php @@ -147,11 +147,11 @@ class installer * @param array $packages Packages to install. * Each entry may be a name or an array associating a version constraint to a name * @param array $whitelist White-listed packages (packages that can be installed/updated/removed) - * @param IOInterface|null $io IO object used for the output + * @param io\io_interface|null $io IO object used for the output * * @throws runtime_exception */ - protected function do_install(array $packages, $whitelist, IOInterface $io = null) + protected function do_install(array $packages, $whitelist, io\io_interface $io = null) { if (!$io) { diff --git a/phpBB/phpbb/composer/manager_interface.php b/phpBB/phpbb/composer/manager_interface.php index 0cf6324661..d14abee8bc 100644 --- a/phpBB/phpbb/composer/manager_interface.php +++ b/phpBB/phpbb/composer/manager_interface.php @@ -57,11 +57,11 @@ interface manager_interface /** * Tells whether or not a package is managed by Composer. * - * @param string $packages Package name + * @param string $package Package name * * @return bool */ - public function is_managed($packages); + public function is_managed($package); /** * Returns the list of managed packages for the current type From ba3a1389e6b217ee688314ec242555c13c121aa3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 16:16:19 +0100 Subject: [PATCH 28/42] [ticket/16955] Clean up config classes PHPBB3-16955 --- phpBB/phpbb/config/config.php | 4 ++-- phpBB/phpbb/template/twig/extension/config.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/config/config.php b/phpBB/phpbb/config/config.php index c40145b457..c1495a15f0 100644 --- a/phpBB/phpbb/config/config.php +++ b/phpBB/phpbb/config/config.php @@ -20,7 +20,7 @@ class config implements \ArrayAccess, \IteratorAggregate, \Countable { /** * The configuration data - * @var array + * @var array */ protected $config; @@ -59,7 +59,7 @@ class config implements \ArrayAccess, \IteratorAggregate, \Countable * Retrieves a configuration value. * * @param string $key The configuration option's name. - * @return string The configuration value + * @return int|string The configuration value */ public function offsetGet($key) { diff --git a/phpBB/phpbb/template/twig/extension/config.php b/phpBB/phpbb/template/twig/extension/config.php index ebb4f0c3ca..e0b8eb440d 100644 --- a/phpBB/phpbb/template/twig/extension/config.php +++ b/phpBB/phpbb/template/twig/extension/config.php @@ -55,7 +55,7 @@ class config extends AbstractExtension /** * Retrieves a configuration value for use in templates. * - * @return string The configuration value + * @return int|string The configuration value */ public function get_config() { From 5756d4dd9bba4f448cd896739584b78291ef78d5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 16:22:34 +0100 Subject: [PATCH 29/42] [ticket/16955] Clean up avatar classes PHPBB3-16955 --- phpBB/phpbb/avatar/driver/driver_interface.php | 2 +- phpBB/phpbb/avatar/driver/upload.php | 2 +- phpBB/phpbb/avatar/manager.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/phpbb/avatar/driver/driver_interface.php b/phpBB/phpbb/avatar/driver/driver_interface.php index 7d6c2cff8a..223f49be20 100644 --- a/phpBB/phpbb/avatar/driver/driver_interface.php +++ b/phpBB/phpbb/avatar/driver/driver_interface.php @@ -95,7 +95,7 @@ interface driver_interface * an array that will be passed to vsprintf() with the language key in * the first array key. * - * @return array Array containing the avatar data as follows: + * @return array|false Array containing the avatar data as follows or false if processing failed: * ['avatar'], ['avatar_width'], ['avatar_height'] */ public function process_form($request, $template, $user, $row, &$error); diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index 433ff7b026..82d1a7fce2 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -284,6 +284,6 @@ class upload extends \phpbb\avatar\driver\driver */ protected function can_upload() { - return $this->php_ini->getBool('file_uploads'); + return (bool) $this->php_ini->getBool('file_uploads'); } } diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 3d85964f5b..5de3caab10 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -29,7 +29,7 @@ class manager /** * Array that contains a list of enabled drivers - * @var array|bool + * @var array|false */ protected static $enabled_drivers = false; @@ -87,7 +87,7 @@ class manager * @param string $avatar_type Avatar type; by default an avatar's service container name * @param bool $load_enabled Load only enabled avatars * - * @return object Avatar driver object + * @return object|null Avatar driver object */ public function get_driver($avatar_type, $load_enabled = true) { @@ -181,7 +181,7 @@ class manager $this->load_enabled_drivers(); } - return self::$enabled_drivers; + return self::$enabled_drivers ?: []; } /** @@ -254,7 +254,7 @@ class manager { $config_name = $driver->get_config_name(); - return $this->config["allow_avatar_{$config_name}"]; + return (bool) $this->config["allow_avatar_{$config_name}"]; } /** From eeeb69b4aebafda1eed2e2414a1ba8347ac27ea5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 17:42:23 +0100 Subject: [PATCH 30/42] [ticket/16955] Clean up auth classes PHPBB3-16955 --- phpBB/phpbb/auth/provider/base.php | 11 -------- phpBB/phpbb/auth/provider/oauth/oauth.php | 15 +++++----- .../auth/provider/oauth/token_storage.php | 4 +-- .../auth/provider/provider_interface.php | 28 +++++++++---------- phpBB/phpbb/db/driver/driver.php | 2 +- 5 files changed, 24 insertions(+), 36 deletions(-) diff --git a/phpBB/phpbb/auth/provider/base.php b/phpBB/phpbb/auth/provider/base.php index 6aab3c2735..97a8b8d4ad 100644 --- a/phpBB/phpbb/auth/provider/base.php +++ b/phpBB/phpbb/auth/provider/base.php @@ -23,7 +23,6 @@ abstract class base implements provider_interface */ public function init() { - return; } /** @@ -31,7 +30,6 @@ abstract class base implements provider_interface */ public function autologin() { - return; } /** @@ -39,7 +37,6 @@ abstract class base implements provider_interface */ public function acp() { - return; } /** @@ -47,7 +44,6 @@ abstract class base implements provider_interface */ public function get_acp_template($new_config) { - return; } /** @@ -55,7 +51,6 @@ abstract class base implements provider_interface */ public function get_login_data() { - return; } /** @@ -63,7 +58,6 @@ abstract class base implements provider_interface */ public function get_auth_link_data($user_id = 0) { - return; } /** @@ -71,7 +65,6 @@ abstract class base implements provider_interface */ public function logout($data, $new_session) { - return; } /** @@ -79,7 +72,6 @@ abstract class base implements provider_interface */ public function validate_session($user) { - return; } /** @@ -87,7 +79,6 @@ abstract class base implements provider_interface */ public function login_link_has_necessary_data(array $login_link_data) { - return; } /** @@ -95,7 +86,6 @@ abstract class base implements provider_interface */ public function link_account(array $link_data) { - return; } /** @@ -103,6 +93,5 @@ abstract class base implements provider_interface */ public function unlink_account(array $link_data) { - return; } } diff --git a/phpBB/phpbb/auth/provider/oauth/oauth.php b/phpBB/phpbb/auth/provider/oauth/oauth.php index cc84bf5dd7..fa84868939 100644 --- a/phpBB/phpbb/auth/provider/oauth/oauth.php +++ b/phpBB/phpbb/auth/provider/oauth/oauth.php @@ -218,7 +218,7 @@ class oauth extends base 'oauth_provider_id' => (string) $unique_id ]; - $sql = 'SELECT user_id + $sql = 'SELECT user_id FROM ' . $this->oauth_account_table . ' WHERE ' . $this->db->sql_build_array('SELECT', $data); $result = $this->db->sql_query($sql); @@ -240,6 +240,7 @@ class oauth extends base * @var ServiceInterface service OAuth service * @since 3.2.3-RC1 * @changed 3.2.6-RC1 Added redirect_data + * @psalm-var string[] $vars */ $vars = [ 'row', @@ -423,8 +424,6 @@ class oauth extends base { return 'LOGIN_LINK_MISSING_DATA'; } - - return null; } /** @@ -618,8 +617,8 @@ class oauth extends base * @param array $link_data The same variable given to * {@see \phpbb\auth\provider\provider_interface::link_account} * @param string $service_name The name of the service being used in linking. - * @return string|false Returns a language constant (string) if an error is encountered, - * or false on success. + * @return array|string|false Returns a language constant (string) if an error is encountered, + * an array with error info or false on success. */ protected function link_account_auth_link(array $link_data, $service_name) { @@ -828,8 +827,8 @@ class oauth extends base * Sets a redirect to the authorization uri. * * @param OAuth1Service|OAuth2Service $service The external OAuth service - * @return array|false Array if an error occurred, - * false on success + * @return array Array if an error occurred, + * won't return on success */ protected function set_redirect($service) { @@ -854,6 +853,6 @@ class oauth extends base redirect($service->getAuthorizationUri($parameters), false, true); - return false; + return []; } } diff --git a/phpBB/phpbb/auth/provider/oauth/token_storage.php b/phpBB/phpbb/auth/provider/oauth/token_storage.php index aa84be9635..73eb194b0f 100644 --- a/phpBB/phpbb/auth/provider/oauth/token_storage.php +++ b/phpBB/phpbb/auth/provider/oauth/token_storage.php @@ -263,7 +263,7 @@ class token_storage implements TokenStorageInterface $data['session_id'] = $this->user->data['session_id']; } - return $this->get_state_row($data); + return $this->get_state_row($data)['oauth_state'] ?? ''; } /** @@ -519,7 +519,7 @@ class token_storage implements TokenStorageInterface * * @param array $data The SQL WHERE data * @return array|false array with the OAuth state row, - * false if the state does not exist + * false if the state does not exist */ protected function get_state_row($data) { diff --git a/phpBB/phpbb/auth/provider/provider_interface.php b/phpBB/phpbb/auth/provider/provider_interface.php index 389f6050f2..43115892be 100644 --- a/phpBB/phpbb/auth/provider/provider_interface.php +++ b/phpBB/phpbb/auth/provider/provider_interface.php @@ -25,8 +25,8 @@ interface provider_interface * Changing to an authentication provider will not be permitted in acp_board * if there is an error. * - * @return boolean|string False if the user is identified, otherwise an - * error message, or null if not implemented. + * @return bool|string|void False if the user is identified, otherwise an + * error message, or void if not implemented. */ public function init(); @@ -52,8 +52,8 @@ interface provider_interface /** * Autologin function * - * @return array|null containing the user row, empty if no auto login - * should take place, or null if not implemented. + * @return array|void containing the user row, empty if no auto login + * should take place, or void if not implemented. */ public function autologin(); @@ -61,7 +61,7 @@ interface provider_interface * This function is used to output any required fields in the authentication * admin panel. It also defines any required configuration table fields. * - * @return array|null Returns null if not implemented or an array of the + * @return array|void Returns void if not implemented or an array of the * configuration fields of the provider. */ public function acp(); @@ -74,7 +74,7 @@ interface provider_interface * * @param \phpbb\config\config $new_config Contains the new configuration values * that have been set in acp_board. - * @return array|null Returns null if not implemented or an array with + * @return array|void Returns void if not implemented or an array with * the template file name and an array of the vars * that the template needs that must conform to the * following example: @@ -107,8 +107,8 @@ interface provider_interface * Returns an array of data necessary to build custom elements on the login * form. * - * @return array|null If this function is not implemented on an auth - * provider then it returns null. If it is implemented + * @return array|void If this function is not implemented on an auth + * provider then it returns void. If it is implemented * it will return an array of up to four elements of * which only 'TEMPLATE_FILE'. If 'BLOCK_VAR_NAME' is * present then 'BLOCK_VARS' must also be present in @@ -139,8 +139,8 @@ interface provider_interface * into phpBB. * * @param array $user - * @return boolean true if the given user is authenticated, false if the - * session should be closed, or null if not implemented. + * @return bool|void true if the given user is authenticated, false if the + * session should be closed, or void if not implemented. */ public function validate_session($user); @@ -151,8 +151,8 @@ interface provider_interface * * @param array $login_link_data Any data needed to link a phpBB account to * an external account. - * @return string|null Returns a string with a language constant if there - * is data missing or null if there is no error. + * @return string|void Returns a string with a language constant if there + * is data missing or void if there is no error. */ public function login_link_has_necessary_data(array $login_link_data); @@ -171,8 +171,8 @@ interface provider_interface * defaults to 0, which is not a valid ID. The method * should fall back to the current user's ID in this * case. - * @return array|null If this function is not implemented on an auth - * provider then it returns null. If it is implemented + * @return array|void If this function is not implemented on an auth + * provider then it returns void. If it is implemented * it will return an array of up to four elements of * which only 'TEMPLATE_FILE'. If 'BLOCK_VAR_NAME' is * present then 'BLOCK_VARS' must also be present in diff --git a/phpBB/phpbb/db/driver/driver.php b/phpBB/phpbb/db/driver/driver.php index a16c6260f4..da4cc80459 100644 --- a/phpBB/phpbb/db/driver/driver.php +++ b/phpBB/phpbb/db/driver/driver.php @@ -571,7 +571,7 @@ abstract class driver implements driver_interface */ function sql_build_array($query, $assoc_ary = []) { - if (!count($assoc_ary)) + if (!is_array($assoc_ary) || !count($assoc_ary)) { return false; } From cedd4476597ede8430fb9fb50cfa29e63351cb86 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 19:52:14 +0100 Subject: [PATCH 31/42] [ticket/16955] Resolve incompatibilities with doctum PHPBB3-16955 --- phpBB/phpbb/db/doctrine/table_helper.php | 3 ++- phpBB/phpbb/db/doctrine/type_converter.php | 3 ++- phpBB/phpbb/db/driver/driver.php | 3 ++- phpBB/phpbb/db/migrator.php | 3 ++- phpBB/phpbb/event/md_exporter.php | 3 ++- phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/phpBB/phpbb/db/doctrine/table_helper.php b/phpBB/phpbb/db/doctrine/table_helper.php index b14571c9f8..935db35838 100644 --- a/phpBB/phpbb/db/doctrine/table_helper.php +++ b/phpBB/phpbb/db/doctrine/table_helper.php @@ -21,7 +21,8 @@ class table_helper * * @param array $column_data Column data. * - * @return array{string, array} A pair of type and array of column options. + * @return array A pair of type and array of column options. + * @psalm-return array{string, array} */ public static function convert_column_data(array $column_data, string $dbms_layer): array { diff --git a/phpBB/phpbb/db/doctrine/type_converter.php b/phpBB/phpbb/db/doctrine/type_converter.php index 61da22eaf1..1de09e821c 100644 --- a/phpBB/phpbb/db/doctrine/type_converter.php +++ b/phpBB/phpbb/db/doctrine/type_converter.php @@ -54,7 +54,8 @@ class type_converter * * @param string $type Legacy type name * - * @return array{string, array} Pair of type name and options. + * @return array Pair of type name and options. + * @psalm-return array{string, array} */ public static function convert(string $type, string $dbms): array { diff --git a/phpBB/phpbb/db/driver/driver.php b/phpBB/phpbb/db/driver/driver.php index da4cc80459..b4220d6e6a 100644 --- a/phpBB/phpbb/db/driver/driver.php +++ b/phpBB/phpbb/db/driver/driver.php @@ -1102,7 +1102,8 @@ abstract class driver implements driver_interface /** * Return sql error array * - * @return array{message: string, code: int|string} SQL error array with message and error code + * @return array SQL error array with message and error code + * @psalm-return array{message: string, code: int|string} */ abstract protected function _sql_error(): array; diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index bdb85a7996..681dfbd735 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -651,7 +651,8 @@ class migrator * @param array $steps The steps to run * @param bool|string $state Current state of the migration * @param bool $revert true to revert a data step - * @return bool|array{result: mixed, step: int} migration state. True if completed, serialized array if not finished + * @return bool|array migration state. True if completed, serialized array if not finished + * @psalm-return bool|array{result: mixed, step: int} * @throws \phpbb\db\migration\exception */ protected function process_data_step($steps, $state, $revert = false) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 5d2155369a..84e04133de 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -461,7 +461,8 @@ class md_exporter * Validate "Changed" Information * * @param string $changed - * @return array{string, string} Changed information containing version and description in respective order + * @return array Changed information containing version and description in respective order + * @psalm-return array{string, string} * @throws \LogicException */ public function validate_changed($changed) diff --git a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php index 06695f5057..b150d7098e 100644 --- a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php +++ b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php @@ -82,7 +82,8 @@ class ajax_iohandler extends iohandler_base protected $redirect_url; /** - * @var resource|closed-resource + * @var resource + * @psalm-var resource|closed-resource */ protected $file_lock_pointer; From 918723e4768ac60e01e600ab08460f184503a5ea Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 21:20:54 +0100 Subject: [PATCH 32/42] [ticket/16955] Clean up phing sniff errors and warnings PHPBB3-16955 --- .../managed_with_clean_error_exception.php | 14 -------------- .../managed_with_enable_error_exception.php | 14 -------------- .../exception/managed_with_error_exception.php | 13 ------------- phpBB/phpbb/console/application.php | 3 --- phpBB/phpbb/storage/storage.php | 2 +- 5 files changed, 1 insertion(+), 45 deletions(-) diff --git a/phpBB/phpbb/composer/exception/managed_with_clean_error_exception.php b/phpBB/phpbb/composer/exception/managed_with_clean_error_exception.php index f7f6d163db..a9a7f9ddbc 100644 --- a/phpBB/phpbb/composer/exception/managed_with_clean_error_exception.php +++ b/phpBB/phpbb/composer/exception/managed_with_clean_error_exception.php @@ -18,18 +18,4 @@ namespace phpbb\composer\exception; */ class managed_with_clean_error_exception extends managed_with_error_exception { - /** - * Constructor - * - * @param string $prefix The language string prefix - * @param string $message The Exception message to throw (must be a language variable). - * @param array $parameters The parameters to use with the language var. - * @param \Exception|null $previous The previous runtime_exception used for the runtime_exception chaining. - * @param integer $code The Exception code. - */ - public function __construct($prefix, $message = '', array $parameters = [], \Exception $previous = null, $code = 0) - { - parent::__construct($prefix, $message, $parameters, $previous, $code); - } - } diff --git a/phpBB/phpbb/composer/exception/managed_with_enable_error_exception.php b/phpBB/phpbb/composer/exception/managed_with_enable_error_exception.php index eace036aed..88c76f5ba9 100644 --- a/phpBB/phpbb/composer/exception/managed_with_enable_error_exception.php +++ b/phpBB/phpbb/composer/exception/managed_with_enable_error_exception.php @@ -18,18 +18,4 @@ namespace phpbb\composer\exception; */ class managed_with_enable_error_exception extends managed_with_error_exception { - /** - * Constructor - * - * @param string $prefix The language string prefix - * @param string $message The Exception message to throw (must be a language variable). - * @param array $parameters The parameters to use with the language var. - * @param \Exception|null $previous The previous runtime_exception used for the runtime_exception chaining. - * @param integer $code The Exception code. - */ - public function __construct($prefix, $message = '', array $parameters = [], \Exception $previous = null, $code = 0) - { - parent::__construct($prefix, $message, $parameters, $previous, $code); - } - } diff --git a/phpBB/phpbb/composer/exception/managed_with_error_exception.php b/phpBB/phpbb/composer/exception/managed_with_error_exception.php index 0ebb1e1adf..a992265b07 100644 --- a/phpBB/phpbb/composer/exception/managed_with_error_exception.php +++ b/phpBB/phpbb/composer/exception/managed_with_error_exception.php @@ -18,17 +18,4 @@ namespace phpbb\composer\exception; */ class managed_with_error_exception extends runtime_exception { - /** - * Constructor - * - * @param string $prefix The language string prefix - * @param string $message The Exception message to throw (must be a language variable). - * @param array $parameters The parameters to use with the language var. - * @param \Exception|null $previous The previous runtime_exception used for the runtime_exception chaining. - * @param integer $code The Exception code. - */ - public function __construct($prefix, $message = '', array $parameters = [], \Exception $previous = null, $code = 0) - { - parent::__construct($prefix, $message, $parameters, $previous, $code); - } } diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 6726904e8f..50443cd646 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -14,10 +14,7 @@ namespace phpbb\console; use Symfony\Component\Console\Input\InputDefinition; -use Symfony\Component\Console\Shell; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Output\OutputInterface; class application extends \Symfony\Component\Console\Application { diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index 671e9da1a3..8e4620ab23 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -403,7 +403,7 @@ class storage * * @param string $path The file * - * @throws \phpbb\storage\exception\exception When the adapter doesnt implement the method + * @throws exception When the adapter doesn't implement the method * When the file doesn't exist * * @return \phpbb\storage\file_info Returns file_info object From 42845125949b0ef8d9819703c039dae2e4efb5ba Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2022 21:25:19 +0100 Subject: [PATCH 33/42] [ticket/16937] Run psalm as part of basic checks in github actions PHPBB3-16937 --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8933843f8a..c2adbb835f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -72,6 +72,10 @@ jobs: run: | .github/check-doctum-parse-errors.sh + - name: Check code with psalm + run: | + phpBB/vendor/bin/psalm --output-format=github + - name: Check image ICC profiles run: | .github/check-image-icc-profiles.sh From fab81eca2bf5c52d9d0015bebab8e7287fcae305 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Dec 2022 17:27:31 +0100 Subject: [PATCH 34/42] [ticket/16955] Add missing docblocks and fix unclear ones PHPBB3-16955 --- build/psalm/stubs/apcu/apcu.php | 11 +++++++++++ build/psalm/stubs/redis/redis.php | 2 -- phpBB/phpbb/auth/provider/oauth/oauth.php | 3 +-- phpBB/phpbb/db/migration/tool/permission.php | 4 ++-- phpBB/phpbb/files/factory.php | 2 +- phpBB/phpbb/files/filespec.php | 4 ++-- phpBB/phpbb/files/filespec_storage.php | 4 ++-- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/build/psalm/stubs/apcu/apcu.php b/build/psalm/stubs/apcu/apcu.php index 55d1463e4d..7fee581ff7 100644 --- a/build/psalm/stubs/apcu/apcu.php +++ b/build/psalm/stubs/apcu/apcu.php @@ -1,4 +1,15 @@ + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ class APCUIterator implements Iterator { diff --git a/build/psalm/stubs/redis/redis.php b/build/psalm/stubs/redis/redis.php index b18c224bd0..96e912f707 100644 --- a/build/psalm/stubs/redis/redis.php +++ b/build/psalm/stubs/redis/redis.php @@ -15,7 +15,5 @@ class Redis { public const OPT_PREFIX = 2; - public const SERIALIZER_PHP = 1; - } diff --git a/phpBB/phpbb/auth/provider/oauth/oauth.php b/phpBB/phpbb/auth/provider/oauth/oauth.php index fa84868939..6925980c94 100644 --- a/phpBB/phpbb/auth/provider/oauth/oauth.php +++ b/phpBB/phpbb/auth/provider/oauth/oauth.php @@ -827,8 +827,7 @@ class oauth extends base * Sets a redirect to the authorization uri. * * @param OAuth1Service|OAuth2Service $service The external OAuth service - * @return array Array if an error occurred, - * won't return on success + * @return array|never Array if an error occurred, won't return on success */ protected function set_redirect($service) { diff --git a/phpBB/phpbb/db/migration/tool/permission.php b/phpBB/phpbb/db/migration/tool/permission.php index 91838a4a47..ca070982bf 100644 --- a/phpBB/phpbb/db/migration/tool/permission.php +++ b/phpBB/phpbb/db/migration/tool/permission.php @@ -266,13 +266,13 @@ class permission implements \phpbb\db\migration\tool\tool_interface * @param string $role_type The type (u_, m_, a_) * @param string $role_description Description of the new role * - * @return int|null Inserted SQL id or false if role already exists + * @return int|null Inserted SQL id or null if role already exists */ public function role_add($role_name, $role_type, $role_description = '') { if ($this->role_exists($role_name)) { - return; + return null; } $sql = 'SELECT MAX(role_order) AS max_role_order diff --git a/phpBB/phpbb/files/factory.php b/phpBB/phpbb/files/factory.php index 6f253d548f..814bddcc20 100644 --- a/phpBB/phpbb/files/factory.php +++ b/phpBB/phpbb/files/factory.php @@ -35,7 +35,7 @@ class factory * * @param string $name Service name * - * @return object|bool Requested service or false if service could not be + * @return object|false Requested service or false if service could not be * found by the container */ public function get($name) diff --git a/phpBB/phpbb/files/filespec.php b/phpBB/phpbb/files/filespec.php index 1ebfdd7cf5..3063b5db33 100644 --- a/phpBB/phpbb/files/filespec.php +++ b/phpBB/phpbb/files/filespec.php @@ -329,7 +329,7 @@ class filespec * Get mime type * * @param string $filename Filename that needs to be checked - * @return string|false Mime type of supplied filename or false if mimetype could not be guessed + * @return string Mime type of supplied filename or empty string if mimetype could not be guessed */ public function get_mimetype($filename) { @@ -343,7 +343,7 @@ class filespec } } - return $this->mimetype; + return $this->mimetype ?: ''; } /** diff --git a/phpBB/phpbb/files/filespec_storage.php b/phpBB/phpbb/files/filespec_storage.php index a241f6f949..f718d82d74 100644 --- a/phpBB/phpbb/files/filespec_storage.php +++ b/phpBB/phpbb/files/filespec_storage.php @@ -313,7 +313,7 @@ class filespec_storage * Get mime type * * @param string $filename Filename that needs to be checked - * @return string|false Mime type of supplied filename or false if mimetype could not be guessed + * @return string Mime type of supplied filename or empty string if mimetype could not be guessed */ public function get_mimetype($filename) { @@ -327,7 +327,7 @@ class filespec_storage } } - return $this->mimetype; + return $this->mimetype ?: ''; } /** From 3b8f6ae4e9d1a0c81d6d8e2b7f88d358f88f966a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Dec 2022 17:28:17 +0100 Subject: [PATCH 35/42] [ticket/16955] Use constants for exit codes in installer console commands PHPBB3-16955 --- .../install/console/command/install/config/show.php | 9 +++++---- .../console/command/install/config/validate.php | 9 +++++---- .../install/console/command/install/install.php | 13 +++++++------ .../install/console/command/update/config/show.php | 9 +++++---- .../console/command/update/config/validate.php | 9 +++++---- .../phpbb/install/console/command/update/update.php | 13 +++++++------ 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/phpBB/phpbb/install/console/command/install/config/show.php b/phpBB/phpbb/install/console/command/install/config/show.php index 58ad7397da..7daede1b04 100644 --- a/phpBB/phpbb/install/console/command/install/config/show.php +++ b/phpBB/phpbb/install/console/command/install/config/show.php @@ -18,6 +18,7 @@ use phpbb\install\installer_configuration; use phpbb\language\language; use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -90,7 +91,7 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message(array('MISSING_FILE', $config_file)); - return 1; + return Command::FAILURE; } try @@ -101,7 +102,7 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_YAML_FILE'); - return 1; + return Command::FAILURE; } $processor = new Processor(); @@ -115,11 +116,11 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage()); - return 1; + return Command::FAILURE; } $style->block(Yaml::dump(array('installer' => $config), 10, 4, true, false)); - return 0; + return Command::SUCCESS; } } diff --git a/phpBB/phpbb/install/console/command/install/config/validate.php b/phpBB/phpbb/install/console/command/install/config/validate.php index 0b8a28beaa..eb638ad387 100644 --- a/phpBB/phpbb/install/console/command/install/config/validate.php +++ b/phpBB/phpbb/install/console/command/install/config/validate.php @@ -18,6 +18,7 @@ use phpbb\install\installer_configuration; use phpbb\language\language; use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -90,7 +91,7 @@ class validate extends \phpbb\console\command\command { $iohandler->add_error_message(array('MISSING_FILE', array($config_file))); - return 1; + return Command::FAILURE; } try @@ -101,7 +102,7 @@ class validate extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_YAML_FILE'); - return 1; + return Command::FAILURE; } $processor = new Processor(); @@ -115,10 +116,10 @@ class validate extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage()); - return 1; + return Command::FAILURE; } $iohandler->add_success_message('CONFIGURATION_VALID'); - return 0; + return Command::SUCCESS; } } diff --git a/phpBB/phpbb/install/console/command/install/install.php b/phpBB/phpbb/install/console/command/install/install.php index e50eeeb5bc..1ad4ea8114 100644 --- a/phpBB/phpbb/install/console/command/install/install.php +++ b/phpBB/phpbb/install/console/command/install/install.php @@ -22,6 +22,7 @@ use phpbb\install\installer_configuration; use phpbb\language\language; use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -111,14 +112,14 @@ class install extends \phpbb\console\command\command { $iohandler->add_error_message('INSTALL_PHPBB_INSTALLED'); - return 1; + return Command::FAILURE; } if (!is_file($config_file)) { $iohandler->add_error_message(array('MISSING_FILE', $config_file)); - return 1; + return Command::FAILURE; } try @@ -129,7 +130,7 @@ class install extends \phpbb\console\command\command { $iohandler->add_error_message(array('INVALID_YAML_FILE', $config_file)); - return 1; + return Command::FAILURE; } $processor = new Processor(); @@ -143,7 +144,7 @@ class install extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage()); - return 1; + return Command::FAILURE; } $this->register_configuration($iohandler, $config); @@ -151,12 +152,12 @@ class install extends \phpbb\console\command\command try { $this->installer->run(); - return 0; + return Command::SUCCESS; } catch (installer_exception $e) { $iohandler->add_error_message($e->getMessage()); - return 1; + return Command::FAILURE; } } diff --git a/phpBB/phpbb/install/console/command/update/config/show.php b/phpBB/phpbb/install/console/command/update/config/show.php index 138c5cae28..df7a69ed31 100644 --- a/phpBB/phpbb/install/console/command/update/config/show.php +++ b/phpBB/phpbb/install/console/command/update/config/show.php @@ -18,6 +18,7 @@ use phpbb\install\updater_configuration; use phpbb\language\language; use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -90,7 +91,7 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message(array('MISSING_FILE', $config_file)); - return 1; + return Command::FAILURE; } try @@ -101,7 +102,7 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_YAML_FILE'); - return 1; + return Command::FAILURE; } $processor = new Processor(); @@ -115,11 +116,11 @@ class show extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage()); - return 1; + return Command::FAILURE; } $style->block(Yaml::dump(array('updater' => $config), 10, 4, true, false)); - return 0; + return Command::SUCCESS; } } diff --git a/phpBB/phpbb/install/console/command/update/config/validate.php b/phpBB/phpbb/install/console/command/update/config/validate.php index 8a0d963ac2..eb1a48546f 100644 --- a/phpBB/phpbb/install/console/command/update/config/validate.php +++ b/phpBB/phpbb/install/console/command/update/config/validate.php @@ -18,6 +18,7 @@ use phpbb\install\updater_configuration; use phpbb\language\language; use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -90,7 +91,7 @@ class validate extends \phpbb\console\command\command { $iohandler->add_error_message(array('MISSING_FILE', array($config_file))); - return 1; + return Command::FAILURE; } try @@ -101,7 +102,7 @@ class validate extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_YAML_FILE'); - return 1; + return Command::FAILURE; } $processor = new Processor(); @@ -115,10 +116,10 @@ class validate extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage()); - return 1; + return Command::FAILURE; } $iohandler->add_success_message('CONFIGURATION_VALID'); - return 0; + return Command::SUCCESS; } } diff --git a/phpBB/phpbb/install/console/command/update/update.php b/phpBB/phpbb/install/console/command/update/update.php index d6e89b2477..f3320d358b 100644 --- a/phpBB/phpbb/install/console/command/update/update.php +++ b/phpBB/phpbb/install/console/command/update/update.php @@ -22,6 +22,7 @@ use phpbb\install\updater_configuration; use phpbb\language\language; use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -111,14 +112,14 @@ class update extends \phpbb\console\command\command { $iohandler->add_error_message('INSTALL_PHPBB_NOT_INSTALLED'); - return 1; + return Command::FAILURE; } if (!is_file($config_file)) { $iohandler->add_error_message(array('MISSING_FILE', $config_file)); - return 1; + return Command::FAILURE; } try @@ -129,7 +130,7 @@ class update extends \phpbb\console\command\command { $iohandler->add_error_message(array('INVALID_YAML_FILE', $config_file)); - return 1; + return Command::FAILURE; } $processor = new Processor(); @@ -143,7 +144,7 @@ class update extends \phpbb\console\command\command { $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage()); - return 1; + return Command::FAILURE; } $this->register_configuration($iohandler, $config); @@ -151,12 +152,12 @@ class update extends \phpbb\console\command\command try { $this->installer->run(); - return 0; + return Command::SUCCESS; } catch (installer_exception $e) { $iohandler->add_error_message($e->getMessage()); - return 1; + return Command::FAILURE; } } From 60aee47f50a395e00c2cb648b4d657cb732253a6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 Dec 2022 22:08:34 +0100 Subject: [PATCH 36/42] [ticket/16955] Replace returns with return in docblock PHPBB3-16955 --- phpBB/phpbb/template/twig/tokenparser/defineparser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/template/twig/tokenparser/defineparser.php b/phpBB/phpbb/template/twig/tokenparser/defineparser.php index a8c83c42bc..14b885a902 100644 --- a/phpBB/phpbb/template/twig/tokenparser/defineparser.php +++ b/phpBB/phpbb/template/twig/tokenparser/defineparser.php @@ -23,7 +23,7 @@ class defineparser extends \Twig\TokenParser\AbstractTokenParser * * @return \Twig\Node\Node A Twig\Node instance * @throws \Twig\Error\SyntaxError - * @returns \phpbb\template\twig\node\definenode + * @return \phpbb\template\twig\node\definenode */ public function parse(\Twig\Token $token) { From 3e8fced5c8994bda300047333d6728c37dd0b8f0 Mon Sep 17 00:00:00 2001 From: Ruben Calvo Date: Sat, 31 Dec 2022 14:58:14 +0100 Subject: [PATCH 37/42] [ticket/16955] Fix phpdoc annotations and return types PHPBB3-16955 --- phpBB/includes/acp/acp_language.php | 2 +- phpBB/includes/acp/acp_storage.php | 2 +- phpBB/includes/diff/diff.php | 47 +++++++++++++--- phpBB/includes/functions.php | 1 + phpBB/includes/functions_admin.php | 2 +- phpBB/includes/functions_compatibility.php | 18 +++--- phpBB/includes/functions_content.php | 9 +-- phpBB/includes/functions_display.php | 8 --- phpBB/phpbb/auth/provider/base.php | 1 + phpBB/phpbb/auth/provider/oauth/oauth.php | 13 +++-- .../auth/provider/provider_interface.php | 2 +- phpBB/phpbb/avatar/manager.php | 2 +- phpBB/phpbb/captcha/plugins/qa.php | 3 +- phpBB/phpbb/composer/installer.php | 2 + phpBB/phpbb/config/config.php | 2 +- .../cron/task/core/prune_shadow_topics.php | 4 +- phpBB/phpbb/db/driver/driver.php | 2 +- phpBB/phpbb/db/driver/driver_interface.php | 2 +- phpBB/phpbb/db/driver/oracle.php | 2 - phpBB/phpbb/db/extractor/mssql_extractor.php | 4 +- .../phpbb/db/extractor/postgres_extractor.php | 2 +- .../phpbb/db/extractor/sqlite3_extractor.php | 2 +- phpBB/phpbb/db/migration/tool/config.php | 2 + phpBB/phpbb/db/migration/tool/config_text.php | 2 + phpBB/phpbb/db/migration/tool/module.php | 9 ++- phpBB/phpbb/db/migration/tool/permission.php | 10 ++-- phpBB/phpbb/db/migrator.php | 56 ++++++++++--------- phpBB/phpbb/di/container_builder.php | 1 + phpBB/phpbb/event/md_exporter.php | 2 +- phpBB/phpbb/event/php_exporter.php | 6 +- phpBB/phpbb/extension/manager.php | 6 +- phpBB/phpbb/file_downloader.php | 2 +- phpBB/phpbb/groupposition/legend.php | 13 +++-- .../console/command/install/config/show.php | 4 +- .../command/install/config/validate.php | 2 +- .../console/command/install/install.php | 6 +- .../console/command/update/config/show.php | 4 +- .../command/update/config/validate.php | 2 +- .../install/console/command/update/update.php | 2 +- phpBB/phpbb/install/controller/install.php | 1 + .../helper/iohandler/ajax_iohandler.php | 4 +- phpBB/phpbb/log/log.php | 4 +- phpBB/phpbb/message/message.php | 20 +++---- phpBB/phpbb/notification/method/email.php | 2 +- .../notification/type/admin_activate_user.php | 6 +- .../phpbb/notification/type/approve_post.php | 4 +- .../phpbb/notification/type/approve_topic.php | 4 +- phpBB/phpbb/notification/type/base.php | 24 +++++++- phpBB/phpbb/notification/type/bookmark.php | 19 +++---- .../notification/type/disapprove_post.php | 4 +- .../notification/type/disapprove_topic.php | 4 +- phpBB/phpbb/notification/type/forum.php | 4 +- phpBB/phpbb/notification/type/pm.php | 4 +- phpBB/phpbb/notification/type/post.php | 4 +- .../phpbb/notification/type/post_in_queue.php | 4 +- phpBB/phpbb/notification/type/quote.php | 4 +- phpBB/phpbb/notification/type/report_pm.php | 4 +- .../notification/type/report_pm_closed.php | 4 +- phpBB/phpbb/notification/type/report_post.php | 4 +- .../notification/type/report_post_closed.php | 4 +- phpBB/phpbb/notification/type/topic.php | 4 +- .../notification/type/topic_in_queue.php | 4 +- phpBB/phpbb/plupload/plupload.php | 14 ++--- phpBB/phpbb/profilefields/type/type_base.php | 1 - phpBB/phpbb/report/controller/report.php | 2 +- phpBB/phpbb/session.php | 4 +- phpBB/phpbb/storage/controller/attachment.php | 2 +- .../twig/tokenparser/defineparser.php | 3 +- phpBB/phpbb/textformatter/s9e/renderer.php | 2 +- phpBB/phpbb/textreparser/base.php | 7 ++- phpBB/phpbb/user.php | 8 ++- tests/template/template_test_case.php | 2 +- tests/text_formatter/s9e/factory_test.php | 10 ++++ 73 files changed, 251 insertions(+), 205 deletions(-) diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php index 82a3e570e5..81b14cc02c 100644 --- a/phpBB/includes/acp/acp_language.php +++ b/phpBB/includes/acp/acp_language.php @@ -99,7 +99,7 @@ class acp_language /** * Main handler for acp_language * - * @param int $id Module ID + * @param string $id Module ID * @param string $mode Module mode */ public function main($id, $mode) diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index 2f651f0e18..adde39baf3 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -55,7 +55,7 @@ class acp_storage public $u_action; /** - * @param string $id + * @param string $id * @param string $mode */ public function main($id, $mode) diff --git a/phpBB/includes/diff/diff.php b/phpBB/includes/diff/diff.php index bed16285a1..8b7d71020a 100644 --- a/phpBB/includes/diff/diff.php +++ b/phpBB/includes/diff/diff.php @@ -340,7 +340,7 @@ class mapped_diff extends diff { if (count($from_lines) != count($mapped_from_lines) || count($to_lines) != count($mapped_to_lines)) { - return false; + return; } parent::__construct($mapped_from_lines, $mapped_to_lines); @@ -760,11 +760,31 @@ class diff3 extends diff */ class diff3_op { + /** + * @var array|mixed + */ + protected $orig; + + /** + * @var array|mixed + */ + protected $final1; + + /** + * @var array|mixed + */ + protected $final2; + + /** + * @var false + */ + protected $_merged; + function __construct($orig = false, $final1 = false, $final2 = false) { - $this->orig = $orig ? $orig : array(); - $this->final1 = $final1 ? $final1 : array(); - $this->final2 = $final2 ? $final2 : array(); + $this->orig = $orig ?: array(); + $this->final1 = $final1 ?: array(); + $this->final2 = $final2 ?: array(); } function merged() @@ -1059,8 +1079,6 @@ class diff3_op return; } - - return; } } @@ -1074,7 +1092,7 @@ class diff3_op_copy extends diff3_op { function __construct($lines = false) { - $this->orig = $lines ? $lines : array(); + $this->orig = $lines ?: array(); $this->final1 = &$this->orig; $this->final2 = &$this->orig; } @@ -1098,6 +1116,21 @@ class diff3_op_copy extends diff3_op */ class diff3_block_builder { + /** + * @var array + */ + protected $orig; + + /** + * @var array + */ + protected $final1; + + /** + * @var array + */ + protected $final2; + function __construct() { $this->_init(); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 05ea03d446..58c142c740 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1694,6 +1694,7 @@ function generate_board_url($without_script_path = false) * @param string $url The url to redirect to * @param bool $return If true, do not redirect but return the sanitized URL. Default is no return. * @param bool $disable_cd_check If true, redirect() will redirect to an external domain. If false, the redirect point to the boards url if it does not match the current domain. Default is false. +* @return string|never */ function redirect($url, $return = false, $disable_cd_check = false) { diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 27f9292ac5..54ba46fb67 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2487,7 +2487,7 @@ function auto_prune($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_fr * @param \phpbb\db\driver\driver_interface $db Database connection * @param \phpbb\cache\driver\driver_interface $cache Cache driver * @param \phpbb\auth\auth $auth Authentication object -* @return null +* @return void */ function phpbb_cache_moderators($db, $cache, $auth) { diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php index 0783035e6c..dd56aa9622 100644 --- a/phpBB/includes/functions_compatibility.php +++ b/phpBB/includes/functions_compatibility.php @@ -122,12 +122,12 @@ function tz_select($default = '', $truncate = false) * must be carried through for the moderators table. * * @deprecated 3.1.0 (To be removed: 4.0.0) -* @return null +* @return void */ function cache_moderators() { global $db, $cache, $auth; - return phpbb_cache_moderators($db, $cache, $auth); + phpbb_cache_moderators($db, $cache, $auth); } /** @@ -249,7 +249,7 @@ function add_log() * if it changes too frequently (true) to be * efficiently cached. * - * @return null + * @return void * * @deprecated 3.1.0 (To be removed: 4.0.0) */ @@ -279,7 +279,7 @@ function set_config($config_name, $config_value, $is_dynamic = false, \phpbb\con * if it changes too frequently (true) to be * efficiently cached. * - * @return null + * @return void * * @deprecated 3.1.0 (To be removed: 4.0.0) */ @@ -336,7 +336,7 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false, $ $static_request = $request; if (empty($var_name)) { - return; + return null; } } else if ($request === false) @@ -344,7 +344,7 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false, $ $static_request = null; if (empty($var_name)) { - return; + return null; } } $tmp_request = $static_request; @@ -575,7 +575,7 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage * Supported types are: MX (default), A, AAAA, NS, TXT, CNAME * Other types may work or may not work * -* @return mixed true if entry found, +* @return bool|null true if entry found, * false if entry not found, * null if this function is not supported by this environment * @@ -615,7 +615,7 @@ function phpbb_inet_ntop($in_addr) * * @param string $address A human readable IPv4 or IPv6 address. * - * @return mixed false if address is invalid, + * @return false|string false if address is invalid, * in_addr representation of the given address otherwise (string) * * @deprecated 3.3.0-b2 (To be removed: 4.0.0) @@ -671,7 +671,7 @@ function phpbb_load_extensions_autoloaders($phpbb_root_path) * * @param array $param Parameter array, see $param_defaults array. * -* @return null +* @return void * * @deprecated 3.2.10 (To be removed 4.0.0) */ diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 783fa67044..349f3582c4 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -144,8 +144,6 @@ function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, 'sorts', ); extract($phpbb_dispatcher->trigger_event('core.gen_sort_selects_after', compact($vars))); - - return; } /** @@ -283,8 +281,6 @@ function make_jumpbox($action, $forum_id = false, $select_all = false, $acl_list 'S_JUMPBOX_ACTION' => $action, 'HIDDEN_FIELDS_FOR_JUMPBOX' => build_hidden_fields($url_parts['params']), )); - - return; } /** @@ -441,6 +437,8 @@ function get_context($text, $words, $length = 400) { return str_replace($characters, $entities, ((utf8_strlen($text) >= $length + 3) ? utf8_substr($text, 0, $length) . '...' : $text)); } + + return ''; } /** @@ -468,7 +466,7 @@ function phpbb_clean_search_string($search_string) * * @param string &$message Original message, passed by reference * @param string $bbcode_uid BBCode UID -* @return null +* @return void */ function decode_message(&$message, $bbcode_uid = '') { @@ -961,7 +959,6 @@ function make_clickable($text, $server_url = false, string $class = 'postlink') if ($value == $static_class) { $element_exists = true; - return; } } ); diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 9a1f33db37..e274ae8476 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -843,8 +843,6 @@ function generate_forum_nav(&$forum_data_ary) $template->assign_block_vars_array('navlinks', $navlinks_parents); $template->assign_block_vars('navlinks', $navlinks); $template->assign_vars($forum_template_data); - - return; } /** @@ -966,8 +964,6 @@ function get_moderators(&$forum_moderators, $forum_id = false) } } $db->sql_freeresult($result); - - return; } /** @@ -999,8 +995,6 @@ function gen_forum_auth_level($mode, $forum_id, $forum_status) { $template->assign_block_vars('rules', array('RULE' => $rule)); } - - return; } /** @@ -1482,8 +1476,6 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $s_watching['title_toggle'] = $user->lang[((!$is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)]; $s_watching['is_watching'] = $is_watching; } - - return; } /** diff --git a/phpBB/phpbb/auth/provider/base.php b/phpBB/phpbb/auth/provider/base.php index 97a8b8d4ad..98945a2ddf 100644 --- a/phpBB/phpbb/auth/provider/base.php +++ b/phpBB/phpbb/auth/provider/base.php @@ -79,6 +79,7 @@ abstract class base implements provider_interface */ public function login_link_has_necessary_data(array $login_link_data) { + return null; } /** diff --git a/phpBB/phpbb/auth/provider/oauth/oauth.php b/phpBB/phpbb/auth/provider/oauth/oauth.php index 6925980c94..a9fd2783b6 100644 --- a/phpBB/phpbb/auth/provider/oauth/oauth.php +++ b/phpBB/phpbb/auth/provider/oauth/oauth.php @@ -424,6 +424,8 @@ class oauth extends base { return 'LOGIN_LINK_MISSING_DATA'; } + + return null; } /** @@ -475,8 +477,6 @@ class oauth extends base // Clear all tokens belonging to the user $storage = new token_storage($this->db, $this->user, $this->oauth_token_table, $this->oauth_state_table); $storage->clearAllTokens(); - - return; } /** @@ -617,7 +617,7 @@ class oauth extends base * @param array $link_data The same variable given to * {@see \phpbb\auth\provider\provider_interface::link_account} * @param string $service_name The name of the service being used in linking. - * @return array|string|false Returns a language constant (string) if an error is encountered, + * @return string|false|never Returns a language constant (string) if an error is encountered, * an array with error info or false on success. */ protected function link_account_auth_link(array $link_data, $service_name) @@ -661,7 +661,9 @@ class oauth extends base } else { - return $this->set_redirect($service); + $this->set_redirect($service); + + return false; // Not reached } } @@ -669,6 +671,7 @@ class oauth extends base * Performs the query that inserts an account link * * @param array $data This array is passed to db->sql_build_array + * @return void */ protected function link_account_perform_link(array $data) { @@ -852,6 +855,6 @@ class oauth extends base redirect($service->getAuthorizationUri($parameters), false, true); - return []; + return []; // Never reached } } diff --git a/phpBB/phpbb/auth/provider/provider_interface.php b/phpBB/phpbb/auth/provider/provider_interface.php index 43115892be..7e1f0a7a84 100644 --- a/phpBB/phpbb/auth/provider/provider_interface.php +++ b/phpBB/phpbb/auth/provider/provider_interface.php @@ -151,7 +151,7 @@ interface provider_interface * * @param array $login_link_data Any data needed to link a phpBB account to * an external account. - * @return string|void Returns a string with a language constant if there + * @return string|null Returns a string with a language constant if there * is data missing or void if there is no error. */ public function login_link_has_necessary_data(array $login_link_data); diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 5de3caab10..17fbae09d9 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -311,7 +311,7 @@ class manager * avatar data * @param string $table Database table from which the avatar should be deleted * @param string $prefix Prefix of user data columns in database - * @return null + * @return void */ public function handle_avatar_delete(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, $avatar_data, $table, $prefix) { diff --git a/phpBB/phpbb/captcha/plugins/qa.php b/phpBB/phpbb/captcha/plugins/qa.php index 811421a63c..b9bfac33f1 100644 --- a/phpBB/phpbb/captcha/plugins/qa.php +++ b/phpBB/phpbb/captcha/plugins/qa.php @@ -1037,7 +1037,8 @@ class qa { return true; } - return false; } + + return false; } } diff --git a/phpBB/phpbb/composer/installer.php b/phpBB/phpbb/composer/installer.php index 354c7ead28..28aaa4171b 100644 --- a/phpBB/phpbb/composer/installer.php +++ b/phpBB/phpbb/composer/installer.php @@ -150,6 +150,7 @@ class installer * @param io\io_interface|null $io IO object used for the output * * @throws runtime_exception + * @throws JsonValidationException */ protected function do_install(array $packages, $whitelist, io\io_interface $io = null) { @@ -501,6 +502,7 @@ class installer * * @param array $packages Packages to update. * Each entry may be a name or an array associating a version constraint to a name + * @throws JsonValidationException */ protected function generate_ext_json_file(array $packages) { diff --git a/phpBB/phpbb/config/config.php b/phpBB/phpbb/config/config.php index c1495a15f0..a63890caf7 100644 --- a/phpBB/phpbb/config/config.php +++ b/phpBB/phpbb/config/config.php @@ -106,7 +106,7 @@ class config implements \ArrayAccess, \IteratorAggregate, \Countable * @param String $key The configuration option's name * @param bool $use_cache Whether this variable should be cached or if it * changes too frequently to be efficiently cached - * @return null + * @return void */ public function delete($key, $use_cache = true) { diff --git a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php index 81873a673b..d95f3e500e 100644 --- a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php +++ b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php @@ -72,7 +72,7 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t /** * Runs this cron task. * - * @return null + * @return void */ public function run() { @@ -135,7 +135,7 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t * * @param \phpbb\request\request_interface $request Request object. * - * @return null + * @return void */ public function parse_parameters(\phpbb\request\request_interface $request) { diff --git a/phpBB/phpbb/db/driver/driver.php b/phpBB/phpbb/db/driver/driver.php index b4220d6e6a..c9b4e8db01 100644 --- a/phpBB/phpbb/db/driver/driver.php +++ b/phpBB/phpbb/db/driver/driver.php @@ -1246,7 +1246,7 @@ abstract class driver implements driver_interface $this->html_hold .= ''; $class = 'row1'; - foreach (array_values($row) as $val) + foreach ($row as $val) { $class = ($class == 'row1') ? 'row2' : 'row1'; $this->html_hold .= '' . (($val) ? $val : ' ') . ''; diff --git a/phpBB/phpbb/db/driver/driver_interface.php b/phpBB/phpbb/db/driver/driver_interface.php index 69a22b3f41..54e3457d3f 100644 --- a/phpBB/phpbb/db/driver/driver_interface.php +++ b/phpBB/phpbb/db/driver/driver_interface.php @@ -365,7 +365,7 @@ interface driver_interface * * @param mixed $query_id Already executed query result, * if false, the last query will be used. - * @return null + * @return void */ public function sql_freeresult($query_id = false); diff --git a/phpBB/phpbb/db/driver/oracle.php b/phpBB/phpbb/db/driver/oracle.php index b777dcfc72..ee4ad9b5f5 100644 --- a/phpBB/phpbb/db/driver/oracle.php +++ b/phpBB/phpbb/db/driver/oracle.php @@ -780,8 +780,6 @@ class oracle extends \phpbb\db\driver\driver $success = @oci_execute($result, OCI_DEFAULT); if ($success) { - array(); - while ($row = oci_fetch_array($result, OCI_ASSOC + OCI_RETURN_NULLS)) { // Take the time spent on parsing rows into account diff --git a/phpBB/phpbb/db/extractor/mssql_extractor.php b/phpBB/phpbb/db/extractor/mssql_extractor.php index 1fa921bc3d..264312a4c4 100644 --- a/phpBB/phpbb/db/extractor/mssql_extractor.php +++ b/phpBB/phpbb/db/extractor/mssql_extractor.php @@ -20,7 +20,7 @@ class mssql_extractor extends base_extractor /** * Writes closing line(s) to database backup * - * @return null + * @return void * @throws extractor_not_initialized_exception when calling this function before init_extractor() */ public function write_end() @@ -310,7 +310,7 @@ class mssql_extractor extends base_extractor * Extracts data from database table (for ODBC driver) * * @param string $table_name name of the database table - * @return null + * @return void * @throws extractor_not_initialized_exception when calling this function before init_extractor() */ protected function write_data_odbc($table_name) diff --git a/phpBB/phpbb/db/extractor/postgres_extractor.php b/phpBB/phpbb/db/extractor/postgres_extractor.php index 2b271104e8..32267ead4a 100644 --- a/phpBB/phpbb/db/extractor/postgres_extractor.php +++ b/phpBB/phpbb/db/extractor/postgres_extractor.php @@ -323,7 +323,7 @@ class postgres_extractor extends base_extractor /** * Writes closing line(s) to database backup * - * @return null + * @return void * @throws extractor_not_initialized_exception when calling this function before init_extractor() */ public function write_end() diff --git a/phpBB/phpbb/db/extractor/sqlite3_extractor.php b/phpBB/phpbb/db/extractor/sqlite3_extractor.php index 92ce9bdcc6..86bb25edde 100644 --- a/phpBB/phpbb/db/extractor/sqlite3_extractor.php +++ b/phpBB/phpbb/db/extractor/sqlite3_extractor.php @@ -135,7 +135,7 @@ class sqlite3_extractor extends base_extractor /** * Writes closing line(s) to database backup * - * @return null + * @return void * @throws extractor_not_initialized_exception when calling this function before init_extractor() */ public function write_end() diff --git a/phpBB/phpbb/db/migration/tool/config.php b/phpBB/phpbb/db/migration/tool/config.php index b5404bdba5..77f1d7cfd1 100644 --- a/phpBB/phpbb/db/migration/tool/config.php +++ b/phpBB/phpbb/db/migration/tool/config.php @@ -161,5 +161,7 @@ class config implements \phpbb\db\migration\tool\tool_interface { return call_user_func_array(array(&$this, $call), $arguments); } + + return null; } } diff --git a/phpBB/phpbb/db/migration/tool/config_text.php b/phpBB/phpbb/db/migration/tool/config_text.php index eb3d5b3385..6080619dfa 100644 --- a/phpBB/phpbb/db/migration/tool/config_text.php +++ b/phpBB/phpbb/db/migration/tool/config_text.php @@ -126,5 +126,7 @@ class config_text implements \phpbb\db\migration\tool\tool_interface { return call_user_func_array(array(&$this, $call), $arguments); } + + return null; } } diff --git a/phpBB/phpbb/db/migration/tool/module.php b/phpBB/phpbb/db/migration/tool/module.php index 7c8f80444e..407945e6db 100644 --- a/phpBB/phpbb/db/migration/tool/module.php +++ b/phpBB/phpbb/db/migration/tool/module.php @@ -339,7 +339,7 @@ class module implements \phpbb\db\migration\tool\tool_interface * Use false to ignore the parent check and check class wide. * @param int|string $module The module id|module_langname * specify that here - * @return null + * @return void * @throws \phpbb\db\migration\exception */ public function remove($class, $parent = 0, $module = '') @@ -350,7 +350,8 @@ class module implements \phpbb\db\migration\tool\tool_interface if (isset($module['module_langname'])) { // Manual Method - return $this->remove($class, $parent, $module['module_langname']); + $this->remove($class, $parent, $module['module_langname']); + return; } // Failed. @@ -443,6 +444,8 @@ class module implements \phpbb\db\migration\tool\tool_interface { return call_user_func_array(array(&$this, $call), $arguments); } + + return null; } /** @@ -470,7 +473,7 @@ class module implements \phpbb\db\migration\tool\tool_interface * key - module_id * value - module_langname * - * @return null + * @return void */ protected function get_categories_list() { diff --git a/phpBB/phpbb/db/migration/tool/permission.php b/phpBB/phpbb/db/migration/tool/permission.php index ca070982bf..80d64b403a 100644 --- a/phpBB/phpbb/db/migration/tool/permission.php +++ b/phpBB/phpbb/db/migration/tool/permission.php @@ -411,7 +411,7 @@ class permission implements \phpbb\db\migration\tool\tool_interface * @param string $type The type (role|group) * @param bool $has_permission True if you want to give them permission, * false if you want to deny them permission - * @return null + * @return void * @throws \phpbb\db\migration\exception */ public function permission_set($name, $auth_option, $type = 'role', $has_permission = true) @@ -506,7 +506,8 @@ class permission implements \phpbb\db\migration\tool\tool_interface if (count($auth_option)) { - return $this->permission_set($role_name, $auth_option, 'role', $has_permission); + $this->permission_set($role_name, $auth_option, 'role', $has_permission); + return; } } @@ -570,7 +571,7 @@ class permission implements \phpbb\db\migration\tool\tool_interface * @param string|array $auth_option The auth_option or array of * auth_options you would like to set * @param string $type The type (role|group) - * @return null + * @return void * @throws \phpbb\db\migration\exception */ public function permission_unset($name, $auth_option, $type = 'role') @@ -643,7 +644,8 @@ class permission implements \phpbb\db\migration\tool\tool_interface throw new \phpbb\db\migration\exception('ROLE_ASSIGNED_NOT_EXIST', $name, $role_id); } - return $this->permission_unset($role_name, $auth_option, 'role'); + $this->permission_unset($role_name, $auth_option, 'role'); + return; } $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index 681dfbd735..60673ea9bc 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -15,6 +15,7 @@ namespace phpbb\db; use phpbb\config\config; use phpbb\db\driver\driver_interface; +use phpbb\db\migration\exception; use phpbb\db\migration\helper; use phpbb\db\output_handler\migrator_output_handler_interface; use phpbb\db\output_handler\null_migrator_output_handler; @@ -157,7 +158,7 @@ class migrator /** * Loads all migrations and their application state from the database. * - * @return null + * @return void */ public function load_migration_state() { @@ -203,7 +204,7 @@ class migrator * Sets the list of available migration class names to the given array. * * @param array $class_names An array of migration class names - * @return null + * @return void */ public function set_migrations($class_names) { @@ -256,7 +257,7 @@ class migrator * The update step can either be a schema or a (partial) data update. To * check if update() needs to be called again use the finished() method. * - * @return null + * @return void */ public function update() { @@ -329,7 +330,7 @@ class migrator * * @param string $name The class name of the migration * @return bool Whether any update step was successfully run - * @throws \phpbb\db\migration\exception + * @throws exception */ protected function try_apply($name) { @@ -365,7 +366,7 @@ class migrator $missing = $this->unfulfillable($depend); if ($missing !== false) { - throw new \phpbb\db\migration\exception('MIGRATION_NOT_FULFILLABLE', $name, $missing); + throw new exception('MIGRATION_NOT_FULFILLABLE', $name, $missing); } if (!isset($this->migration_state[$depend]) || @@ -480,7 +481,7 @@ class migrator $this->output_handler->write(array('MIGRATION_DATA_IN_PROGRESS', $name, $elapsed_time), migrator_output_handler_interface::VERBOSITY_VERY_VERBOSE); } } - catch (\phpbb\db\migration\exception $e) + catch (exception $e) { // Reset data state and revert the schema changes $state['migration_data_state'] = ''; @@ -653,7 +654,7 @@ class migrator * @param bool $revert true to revert a data step * @return bool|array migration state. True if completed, serialized array if not finished * @psalm-return bool|array{result: mixed, step: int} - * @throws \phpbb\db\migration\exception + * @throws exception */ protected function process_data_step($steps, $state, $revert = false) { @@ -693,7 +694,7 @@ class migrator ); } } - catch (\phpbb\db\migration\exception $e) + catch (exception $e) { // We should try rolling back here foreach ($steps as $reverse_step_identifier => $reverse_step) @@ -715,15 +716,16 @@ class migrator } /** - * Run a single step - * - * An exception should be thrown if an error occurs - * - * @param mixed $step Data step from migration - * @param mixed $last_result Result to pass to the callable (only for 'custom' method) - * @param bool $reverse False to install, True to attempt uninstallation by reversing the call - * @return null - */ + * Run a single step + * + * An exception should be thrown if an error occurs + * + * @param mixed $step Data step from migration + * @param mixed $last_result Result to pass to the callable (only for 'custom' method) + * @param bool $reverse False to install, True to attempt uninstallation by reversing the call + * @return mixed + * @throws exception + */ protected function run_step($step, $last_result = 0, $reverse = false) { $callable_and_parameters = $this->get_callable_from_step($step, $last_result, $reverse); @@ -747,7 +749,7 @@ class migrator * @param bool $reverse False to install, True to attempt uninstallation by reversing the call * @return array|false Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters; * false if no callable can be created from data setp - * @throws \phpbb\db\migration\exception + * @throws exception */ protected function get_callable_from_step(array $step, $last_result = 0, $reverse = false) { @@ -769,12 +771,12 @@ class migrator case 'if': if (!isset($parameters[0])) { - throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_MISSING_CONDITION', $step); + throw new exception('MIGRATION_INVALID_DATA_MISSING_CONDITION', $step); } if (!isset($parameters[1])) { - throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_MISSING_STEP', $step); + throw new exception('MIGRATION_INVALID_DATA_MISSING_STEP', $step); } if ($reverse) @@ -799,7 +801,7 @@ class migrator case 'custom': if (!is_callable($parameters[0])) { - throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step); + throw new exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step); } if ($reverse) @@ -818,17 +820,17 @@ class migrator default: if (!$method) { - throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_UNKNOWN_TYPE', $step); + throw new exception('MIGRATION_INVALID_DATA_UNKNOWN_TYPE', $step); } if (!isset($this->tools[$class])) { - throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_UNDEFINED_TOOL', $step); + throw new exception('MIGRATION_INVALID_DATA_UNDEFINED_TOOL', $step); } if (!method_exists(get_class($this->tools[$class]), $method)) { - throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_UNDEFINED_METHOD', $step); + throw new exception('MIGRATION_INVALID_DATA_UNDEFINED_METHOD', $step); } // Attempt to reverse operations @@ -855,7 +857,7 @@ class migrator * * @param string $name Name of the migration * @param array $state - * @return null + * @return void */ protected function set_migration_state($name, $state) { @@ -993,7 +995,7 @@ class migrator * THIS WILL THROW ERRORS IF MIGRATIONS ALREADY EXIST IN THE TABLE, DO NOT CALL MORE THAN ONCE! * * @param array $migrations Array of migrations (names) to add to the migrations table - * @return null + * @return void */ public function populate_migrations($migrations) { @@ -1016,7 +1018,7 @@ class migrator /** * Creates the migrations table if it does not exist. - * @return null + * @return void */ public function create_migrations_table() { diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index b9dc8bba63..33852ba08c 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -143,6 +143,7 @@ class container_builder * Build and return a new Container respecting the current configuration * * @return \phpbb_cache_container|ContainerBuilder + * @throws \Exception */ public function get_container() { diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 84e04133de..fcc5b78afc 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -429,7 +429,7 @@ class md_exporter * Validates a template event name * * @param $event_name - * @return null + * @return void * @throws \LogicException */ public function validate_event_name($event_name) diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index ba8ffbbe36..2dfb877fa6 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -84,7 +84,7 @@ class php_exporter * * @param string $name Name of the current event (used for error messages) * @param int $line Line where the current event is placed in - * @return null + * @return void */ public function set_current_event($name, $line) { @@ -96,7 +96,7 @@ class php_exporter * Set the content of this file * * @param array $content Array with the lines of the file - * @return null + * @return void */ public function set_content($content) { @@ -790,7 +790,7 @@ class php_exporter * * @param array $vars_array Variables found in the array line * @param array $vars_docblock Variables found in the doc block - * @return null + * @return void * @throws \LogicException */ public function validate_vars_docblock_array($vars_array, $vars_docblock) diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 27257239f6..24dfeb75b4 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -254,7 +254,7 @@ class manager * so never call this in a script that has a max_execution time. * * @param string $name The extension's name - * @return null + * @return void */ public function enable($name) { @@ -302,7 +302,7 @@ class manager * while so never call this in a script that has a max_execution time. * * @param string $name The extension's name - * @return null + * @return void */ public function disable($name) { @@ -357,7 +357,7 @@ class manager * so never call this in a script that has a max_execution time. * * @param string $name The extension's name - * @return null + * @return void */ public function purge($name) { diff --git a/phpBB/phpbb/file_downloader.php b/phpBB/phpbb/file_downloader.php index 75721b0f05..873bccc9e8 100644 --- a/phpBB/phpbb/file_downloader.php +++ b/phpBB/phpbb/file_downloader.php @@ -30,7 +30,7 @@ class file_downloader * @param int $port Port to connect to; default: 80 * @param int $timeout Connection timeout in seconds; default: 6 * - * @return mixed File data as string if file can be read and there is no + * @return false|string File data as string if file can be read and there is no * timeout, false if there were errors or the connection timed out * * @throws \phpbb\exception\runtime_exception If data can't be retrieved and no error diff --git a/phpBB/phpbb/groupposition/legend.php b/phpBB/phpbb/groupposition/legend.php index fb4ea44af6..fd20896473 100644 --- a/phpBB/phpbb/groupposition/legend.php +++ b/phpBB/phpbb/groupposition/legend.php @@ -110,12 +110,13 @@ class legend implements \phpbb\groupposition\groupposition_interface } /** - * Deletes a group by setting the field to self::GROUP_DISABLED and closing the gap in the list. - * - * @param int $group_id group_id of the group to be deleted - * @param bool $skip_group Skip setting the value for this group, to save the query, when you need to update it anyway. - * @return bool True if the group was deleted successfully - */ + * Deletes a group by setting the field to self::GROUP_DISABLED and closing the gap in the list. + * + * @param int $group_id group_id of the group to be deleted + * @param bool $skip_group Skip setting the value for this group, to save the query, when you need to update it anyway. + * @return bool True if the group was deleted successfully + * @throws exception + */ public function delete_group($group_id, $skip_group = false) { $current_value = $this->get_group_value($group_id); diff --git a/phpBB/phpbb/install/console/command/install/config/show.php b/phpBB/phpbb/install/console/command/install/config/show.php index 7daede1b04..138f74e74f 100644 --- a/phpBB/phpbb/install/console/command/install/config/show.php +++ b/phpBB/phpbb/install/console/command/install/config/show.php @@ -96,7 +96,7 @@ class show extends \phpbb\console\command\command try { - $config = Yaml::parse(file_get_contents($config_file), true, false); + $config = Yaml::parse(file_get_contents($config_file), true); } catch (ParseException $e) { @@ -119,7 +119,7 @@ class show extends \phpbb\console\command\command return Command::FAILURE; } - $style->block(Yaml::dump(array('installer' => $config), 10, 4, true, false)); + $style->block(Yaml::dump(array('installer' => $config), 10, 4, true)); return Command::SUCCESS; } diff --git a/phpBB/phpbb/install/console/command/install/config/validate.php b/phpBB/phpbb/install/console/command/install/config/validate.php index eb638ad387..2682756c13 100644 --- a/phpBB/phpbb/install/console/command/install/config/validate.php +++ b/phpBB/phpbb/install/console/command/install/config/validate.php @@ -96,7 +96,7 @@ class validate extends \phpbb\console\command\command try { - $config = Yaml::parse(file_get_contents($config_file), true, false); + $config = Yaml::parse(file_get_contents($config_file), true); } catch (ParseException $e) { diff --git a/phpBB/phpbb/install/console/command/install/install.php b/phpBB/phpbb/install/console/command/install/install.php index 1ad4ea8114..84c8aa688a 100644 --- a/phpBB/phpbb/install/console/command/install/install.php +++ b/phpBB/phpbb/install/console/command/install/install.php @@ -16,6 +16,7 @@ namespace phpbb\install\console\command\install; use phpbb\install\exception\installer_exception; use phpbb\install\helper\install_helper; use phpbb\install\helper\iohandler\cli_iohandler; +use phpbb\install\helper\iohandler\exception\iohandler_not_implemented_exception; use phpbb\install\helper\iohandler\factory; use phpbb\install\installer; use phpbb\install\installer_configuration; @@ -90,10 +91,11 @@ class install extends \phpbb\console\command\command * * Install the board * - * @param InputInterface $input An InputInterface instance + * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return int 0 if everything went fine, or a non-zero exit code + * @throws iohandler_not_implemented_exception */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -124,7 +126,7 @@ class install extends \phpbb\console\command\command try { - $config = Yaml::parse(file_get_contents($config_file), true, false); + $config = Yaml::parse(file_get_contents($config_file), true); } catch (ParseException $e) { diff --git a/phpBB/phpbb/install/console/command/update/config/show.php b/phpBB/phpbb/install/console/command/update/config/show.php index df7a69ed31..85f90e14aa 100644 --- a/phpBB/phpbb/install/console/command/update/config/show.php +++ b/phpBB/phpbb/install/console/command/update/config/show.php @@ -96,7 +96,7 @@ class show extends \phpbb\console\command\command try { - $config = Yaml::parse(file_get_contents($config_file), true, false); + $config = Yaml::parse(file_get_contents($config_file), true); } catch (ParseException $e) { @@ -119,7 +119,7 @@ class show extends \phpbb\console\command\command return Command::FAILURE; } - $style->block(Yaml::dump(array('updater' => $config), 10, 4, true, false)); + $style->block(Yaml::dump(array('updater' => $config), 10, 4, true)); return Command::SUCCESS; } diff --git a/phpBB/phpbb/install/console/command/update/config/validate.php b/phpBB/phpbb/install/console/command/update/config/validate.php index eb1a48546f..69fba0f7a8 100644 --- a/phpBB/phpbb/install/console/command/update/config/validate.php +++ b/phpBB/phpbb/install/console/command/update/config/validate.php @@ -96,7 +96,7 @@ class validate extends \phpbb\console\command\command try { - $config = Yaml::parse(file_get_contents($config_file), true, false); + $config = Yaml::parse(file_get_contents($config_file), true); } catch (ParseException $e) { diff --git a/phpBB/phpbb/install/console/command/update/update.php b/phpBB/phpbb/install/console/command/update/update.php index f3320d358b..3c70231c20 100644 --- a/phpBB/phpbb/install/console/command/update/update.php +++ b/phpBB/phpbb/install/console/command/update/update.php @@ -124,7 +124,7 @@ class update extends \phpbb\console\command\command try { - $config = Yaml::parse(file_get_contents($config_file), true, false); + $config = Yaml::parse(file_get_contents($config_file), true); } catch (ParseException $e) { diff --git a/phpBB/phpbb/install/controller/install.php b/phpBB/phpbb/install/controller/install.php index 47acc2953f..df6da1e3db 100644 --- a/phpBB/phpbb/install/controller/install.php +++ b/phpBB/phpbb/install/controller/install.php @@ -99,6 +99,7 @@ class install * @return Response|StreamedResponse * * @throws http_exception When phpBB is already installed + * @throws \phpbb\install\helper\iohandler\exception\iohandler_not_implemented_exception * @psalm-suppress InvalidNullableReturnType */ public function handle() diff --git a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php index b150d7098e..62ef42108d 100644 --- a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php +++ b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php @@ -94,9 +94,9 @@ class ajax_iohandler extends iohandler_base * @param \phpbb\request\request_interface $request HTTP request interface * @param \phpbb\template\template $template Template engine * @param router $router Router - * @param string $root_path Path to phpBB's root + * @param string $root_path Path to phpBB's root */ - public function __construct(path_helper $path_helper, \phpbb\request\request_interface $request, \phpbb\template\template $template, router $router, $root_path) + public function __construct(path_helper $path_helper, \phpbb\request\request_interface $request, \phpbb\template\template $template, router $router, string $root_path) { $this->path_helper = $path_helper; $this->request = $request; diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index 385251eaab..054e8bdda8 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -129,7 +129,7 @@ class log implements \phpbb\log\log_interface * in get_logs() * * @param bool $is_in_admin Are we called from within the acp? - * @return null + * @return void */ public function set_is_admin($is_in_admin) { @@ -150,7 +150,7 @@ class log implements \phpbb\log\log_interface * Set table name * * @param string $log_table Can overwrite the table to use for the logs - * @return null + * @return void */ public function set_log_table($log_table) { diff --git a/phpBB/phpbb/message/message.php b/phpBB/phpbb/message/message.php index 53821d5412..d77f56c73f 100644 --- a/phpBB/phpbb/message/message.php +++ b/phpBB/phpbb/message/message.php @@ -65,7 +65,7 @@ class message * Set the subject of the email * * @param string $subject - * @return null + * @return void */ public function set_subject($subject) { @@ -76,7 +76,7 @@ class message * Set the body of the email text * * @param string $body - * @return null + * @return void */ public function set_body($body) { @@ -87,7 +87,7 @@ class message * Set the name of the email template to use * * @param string $template - * @return null + * @return void */ public function set_template($template) { @@ -98,7 +98,7 @@ class message * Set the array with the "template" data for the email * * @param array $template_vars - * @return null + * @return void */ public function set_template_vars($template_vars) { @@ -109,7 +109,7 @@ class message * Add a recipient from \phpbb\user * * @param array $user - * @return null + * @return void */ public function add_recipient_from_user_row(array $user) { @@ -132,7 +132,7 @@ class message * @param int $recipient_notify_type Used notification methods (Jabber, Email, ...) * @param string $recipient_username User Name (used for AntiAbuse header) * @param string $recipient_jabber - * @return null + * @return void */ public function add_recipient($recipient_name, $recipient_address, $recipient_lang, $recipient_notify_type = NOTIFY_EMAIL, $recipient_username = '', $recipient_jabber = '') { @@ -151,7 +151,7 @@ class message * Set the senders data from \phpbb\user object * * @param \phpbb\user $user - * @return null + * @return void */ public function set_sender_from_user($user) { @@ -178,7 +178,7 @@ class message * @param int $sender_id User ID * @param string $sender_username User Name (used for AntiAbuse header) * @param string $sender_jabber - * @return null + * @return void */ public function set_sender($sender_ip, $sender_name, $sender_address, $sender_lang = '', $sender_id = 0, $sender_username = '', $sender_jabber = '') { @@ -195,7 +195,7 @@ class message * Which notification type should be used? Jabber, Email, ...? * * @param int $sender_notify_type - * @return null + * @return void */ public function set_sender_notify_type($sender_notify_type) { @@ -205,7 +205,7 @@ class message /** * Ok, now the same email if CC specified, but without exposing the user's email address * - * @return null + * @return void */ public function cc_sender() { diff --git a/phpBB/phpbb/notification/method/email.php b/phpBB/phpbb/notification/method/email.php index ce81c58185..cffd259c0e 100644 --- a/phpBB/phpbb/notification/method/email.php +++ b/phpBB/phpbb/notification/method/email.php @@ -117,7 +117,7 @@ class email extends \phpbb\notification\method\messenger_base $insert_buffer->flush(); - return $this->notify_using_messenger(NOTIFY_EMAIL); + $this->notify_using_messenger(NOTIFY_EMAIL); } /** diff --git a/phpBB/phpbb/notification/type/admin_activate_user.php b/phpBB/phpbb/notification/type/admin_activate_user.php index 1d8d5717f4..99a758c116 100644 --- a/phpBB/phpbb/notification/type/admin_activate_user.php +++ b/phpBB/phpbb/notification/type/admin_activate_user.php @@ -29,8 +29,10 @@ class admin_activate_user extends \phpbb\notification\type\base } /** - * {@inheritdoc} - */ + * Language key used to output the text + * + * @var string + */ protected $language_key = 'NOTIFICATION_ADMIN_ACTIVATE_USER'; /** diff --git a/phpBB/phpbb/notification/type/approve_post.php b/phpBB/phpbb/notification/type/approve_post.php index 98b04cc7cc..7c242b75da 100644 --- a/phpBB/phpbb/notification/type/approve_post.php +++ b/phpBB/phpbb/notification/type/approve_post.php @@ -128,9 +128,7 @@ class approve_post extends \phpbb\notification\type\post } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/approve_topic.php b/phpBB/phpbb/notification/type/approve_topic.php index d072ff330a..c28d94e3f5 100644 --- a/phpBB/phpbb/notification/type/approve_topic.php +++ b/phpBB/phpbb/notification/type/approve_topic.php @@ -127,9 +127,7 @@ class approve_topic extends \phpbb\notification\type\topic } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index 7c77154fe7..54a9319d26 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -129,7 +129,7 @@ abstract class base implements \phpbb\notification\type\type_interface */ public function __get($name) { - return (!isset($this->data[$name])) ? null : $this->data[$name]; + return $this->data[$name] ?? null; } @@ -139,13 +139,24 @@ abstract class base implements \phpbb\notification\type\type_interface * @param mixed $name * @param mixed $value * - * @return null + * @return void */ public function __set($name, $value) { $this->data[$name] = $value; } + /** + * Magic method check if a variable is defined and is not null + * + * @param mixed $name + * + * @return bool + */ + public function __isset($name) + { + return isset($this->data[$name]); + } /** * Magic method to get a string of this notification @@ -394,7 +405,6 @@ abstract class base implements \phpbb\notification\type\type_interface */ public function load_special($data, $notifications) { - return; } /** @@ -407,6 +417,14 @@ abstract class base implements \phpbb\notification\type\type_interface return true; } + /** + * {@inheritdoc} + */ + public function get_email_template() + { + return false; + } + /** * Pre create insert array function (fall back) * diff --git a/phpBB/phpbb/notification/type/bookmark.php b/phpBB/phpbb/notification/type/bookmark.php index 487e3a7543..98a759c300 100644 --- a/phpBB/phpbb/notification/type/bookmark.php +++ b/phpBB/phpbb/notification/type/bookmark.php @@ -57,13 +57,14 @@ class bookmark extends \phpbb\notification\type\post } /** - * Find the users who want to receive notifications - * - * @param array $type_data Data from submit_post - * @param array $options Options for finding users for notification - * - * @return array - */ + * Find the users who want to receive notifications + * + * @param array $type_data Data from submit_post + * @param array $options Options for finding users for notification + * + * @return array + * @throws \Exception + */ public function find_users_for_notification($type_data, $options = array()) { $options = array_merge(array( @@ -117,9 +118,7 @@ class bookmark extends \phpbb\notification\type\post } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/disapprove_post.php b/phpBB/phpbb/notification/type/disapprove_post.php index a92a69cf03..b7805dd0ec 100644 --- a/phpBB/phpbb/notification/type/disapprove_post.php +++ b/phpBB/phpbb/notification/type/disapprove_post.php @@ -148,9 +148,7 @@ class disapprove_post extends \phpbb\notification\type\approve_post } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/disapprove_topic.php b/phpBB/phpbb/notification/type/disapprove_topic.php index d5e9b64804..5b9d03d238 100644 --- a/phpBB/phpbb/notification/type/disapprove_topic.php +++ b/phpBB/phpbb/notification/type/disapprove_topic.php @@ -148,9 +148,7 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/forum.php b/phpBB/phpbb/notification/type/forum.php index 2d196f013f..181316e922 100644 --- a/phpBB/phpbb/notification/type/forum.php +++ b/phpBB/phpbb/notification/type/forum.php @@ -104,9 +104,7 @@ class forum extends \phpbb\notification\type\post } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/pm.php b/phpBB/phpbb/notification/type/pm.php index 8dffbc1bf4..276d1984fb 100644 --- a/phpBB/phpbb/notification/type/pm.php +++ b/phpBB/phpbb/notification/type/pm.php @@ -145,9 +145,7 @@ class pm extends \phpbb\notification\type\base } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index 022e184110..be8c8d75e9 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -238,9 +238,7 @@ class post extends \phpbb\notification\type\base } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/post_in_queue.php b/phpBB/phpbb/notification/type/post_in_queue.php index a02dd9684e..3d818a1b27 100644 --- a/phpBB/phpbb/notification/type/post_in_queue.php +++ b/phpBB/phpbb/notification/type/post_in_queue.php @@ -152,9 +152,7 @@ class post_in_queue extends \phpbb\notification\type\post } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/quote.php b/phpBB/phpbb/notification/type/quote.php index f8fd8e4d81..98224917e9 100644 --- a/phpBB/phpbb/notification/type/quote.php +++ b/phpBB/phpbb/notification/type/quote.php @@ -149,9 +149,7 @@ class quote extends \phpbb\notification\type\post } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/report_pm.php b/phpBB/phpbb/notification/type/report_pm.php index c8a1ccae69..f542eccf20 100644 --- a/phpBB/phpbb/notification/type/report_pm.php +++ b/phpBB/phpbb/notification/type/report_pm.php @@ -125,9 +125,7 @@ class report_pm extends \phpbb\notification\type\pm } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/report_pm_closed.php b/phpBB/phpbb/notification/type/report_pm_closed.php index 083baeece8..06186a868c 100644 --- a/phpBB/phpbb/notification/type/report_pm_closed.php +++ b/phpBB/phpbb/notification/type/report_pm_closed.php @@ -84,9 +84,7 @@ class report_pm_closed extends \phpbb\notification\type\pm } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/report_post.php b/phpBB/phpbb/notification/type/report_post.php index 730a6a12f4..1aeac139eb 100644 --- a/phpBB/phpbb/notification/type/report_post.php +++ b/phpBB/phpbb/notification/type/report_post.php @@ -91,9 +91,7 @@ class report_post extends \phpbb\notification\type\post_in_queue } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/report_post_closed.php b/phpBB/phpbb/notification/type/report_post_closed.php index 9e05e4c9cd..e71901a61c 100644 --- a/phpBB/phpbb/notification/type/report_post_closed.php +++ b/phpBB/phpbb/notification/type/report_post_closed.php @@ -91,9 +91,7 @@ class report_post_closed extends \phpbb\notification\type\post } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/topic.php b/phpBB/phpbb/notification/type/topic.php index 715e0d47ed..7ecb5e6e85 100644 --- a/phpBB/phpbb/notification/type/topic.php +++ b/phpBB/phpbb/notification/type/topic.php @@ -191,9 +191,7 @@ class topic extends \phpbb\notification\type\base } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/notification/type/topic_in_queue.php b/phpBB/phpbb/notification/type/topic_in_queue.php index 523b8eb5a3..bfdec5278b 100644 --- a/phpBB/phpbb/notification/type/topic_in_queue.php +++ b/phpBB/phpbb/notification/type/topic_in_queue.php @@ -144,9 +144,7 @@ class topic_in_queue extends \phpbb\notification\type\topic } /** - * Get email template - * - * @return string|bool + * {@inheritdoc} */ public function get_email_template() { diff --git a/phpBB/phpbb/plupload/plupload.php b/phpBB/phpbb/plupload/plupload.php index ed749fdbe0..aeb1bd87d2 100644 --- a/phpBB/phpbb/plupload/plupload.php +++ b/phpBB/phpbb/plupload/plupload.php @@ -100,7 +100,7 @@ class plupload // and handle the file as usual if ($chunks_expected < 2) { - return; + return null; } $file_name = $this->request->variable('name', ''); @@ -150,7 +150,7 @@ class plupload * @param int $forum_id The ID of the forum * @param int $max_files Maximum number of files allowed. 0 for unlimited. * - * @return null + * @return void */ public function configure(\phpbb\cache\service $cache, \phpbb\template\template $template, $s_action, $forum_id, $max_files) { @@ -200,7 +200,7 @@ class plupload * @param int $code The error code * @param string $msg The translation string of the message to be sent * - * @return null + * @return void */ public function emit_error($code, $msg) { @@ -331,7 +331,7 @@ class plupload * @param int $chunk Chunk number * @param string $file_path File path * - * @return null + * @return void */ protected function integrate_uploaded_file($form_name, $chunk, $file_path) { @@ -378,7 +378,7 @@ class plupload /** * Creates the temporary directory if it does not already exist. * - * @return null + * @return void */ protected function prepare_temporary_directory() { @@ -396,7 +396,7 @@ class plupload /** * Sets the default directories for uploads * - * @return null + * @return void */ protected function set_default_directories() { @@ -410,7 +410,7 @@ class plupload * @param string $upload_directory Upload directory * @param string $temporary_directory Temporary directory * - * @return null + * @return void */ public function set_upload_directories($upload_directory, $temporary_directory) { diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 8fe4b38c46..80a535cb1f 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -179,7 +179,6 @@ abstract class type_base implements type_interface */ public function display_options(&$template_vars, &$field_data) { - return; } /** diff --git a/phpBB/phpbb/report/controller/report.php b/phpBB/phpbb/report/controller/report.php index 026f450d85..1af565e6a0 100644 --- a/phpBB/phpbb/report/controller/report.php +++ b/phpBB/phpbb/report/controller/report.php @@ -258,7 +258,7 @@ class report * @param array $error * @param string $s_hidden_fields * @param mixed $captcha - * @return null + * @return void */ protected function assign_template_data($mode, $id, $reason_id, $report_text, $user_notify, $error = array(), $s_hidden_fields = '', $captcha = false) { diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php index d311f3758e..0d401c86e1 100644 --- a/phpBB/phpbb/session.php +++ b/phpBB/phpbb/session.php @@ -1068,8 +1068,6 @@ class session * @since 3.1.6-RC1 */ $phpbb_dispatcher->trigger_event('core.session_gc_after'); - - return; } /** @@ -1143,7 +1141,7 @@ class session if (defined('IN_CHECK_BAN') || defined('SKIP_CHECK_BAN')) { - return; + return false; } $banned = false; diff --git a/phpBB/phpbb/storage/controller/attachment.php b/phpBB/phpbb/storage/controller/attachment.php index 11d254f24a..08cd012290 100644 --- a/phpBB/phpbb/storage/controller/attachment.php +++ b/phpBB/phpbb/storage/controller/attachment.php @@ -289,7 +289,7 @@ class attachment extends controller */ protected function filenameFallback($filename) { - $filename = preg_replace(['/[^\x20-\x7e]/', '/%/', '/\//', '/\\\/'], '', $filename); + $filename = preg_replace(['/[^\x20-\x7e]/', '/%/', '/\//', '/\\\\/'], '', $filename); return (!empty($filename)) ?: 'File'; } diff --git a/phpBB/phpbb/template/twig/tokenparser/defineparser.php b/phpBB/phpbb/template/twig/tokenparser/defineparser.php index 14b885a902..ce394c0896 100644 --- a/phpBB/phpbb/template/twig/tokenparser/defineparser.php +++ b/phpBB/phpbb/template/twig/tokenparser/defineparser.php @@ -21,9 +21,8 @@ class defineparser extends \Twig\TokenParser\AbstractTokenParser * * @param \Twig\Token $token A Twig\Token instance * - * @return \Twig\Node\Node A Twig\Node instance * @throws \Twig\Error\SyntaxError - * @return \phpbb\template\twig\node\definenode + * @return \Twig\Node\Node A Twig\Node instance */ public function parse(\Twig\Token $token) { diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 855e034b14..8328b65a95 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -148,7 +148,7 @@ class renderer implements \phpbb\textformatter\renderer_interface * * @param \phpbb\config\config $config * @param \phpbb\path_helper $path_helper - * @return null + * @return void */ public function configure_smilies_path(\phpbb\config\config $config, \phpbb\path_helper $path_helper) { diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index c4b344f8db..6ac30a0002 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -40,8 +40,11 @@ abstract class base implements reparser_interface abstract protected function get_records_by_range($min_id, $max_id); /** - * {@inheritdoc} - */ + * Save record + * + * @param array $record + * @return void + */ abstract protected function save_record(array $record); /** diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index 2e7ab22651..52427d2915 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -470,14 +470,18 @@ class user extends \phpbb\session * @param $number int|float The number we want to get the plural case for. Float numbers are floored. * @param $force_rule mixed False to use the plural rule of the language package * or an integer to force a certain plural rule - * @return int|bool The plural-case we need to use for the number plural-rule combination, false if $force_rule + * @return int|false The plural-case we need to use for the number plural-rule combination, false if $force_rule * was invalid. * * @deprecated: 3.2.0-dev (To be removed: 4.0.0) */ function get_plural_form($number, $force_rule = false) { - return $this->language->get_plural_form($number, $force_rule); + try { + return $this->language->get_plural_form($number, $force_rule); + } catch (\phpbb\language\exception\invalid_plural_rule_exception $e) { + return false; + } } /** diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index fc24600799..9a06c06dc9 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -110,7 +110,7 @@ class phpbb_template_template_test_case extends phpbb_test_case 'autoescape' => false, ) ); - $this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user))); + $this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $lang))); $twig->setLexer(new \phpbb\template\twig\lexer($twig)); $this->template->set_custom_style('tests', $this->template_path); } diff --git a/tests/text_formatter/s9e/factory_test.php b/tests/text_formatter/s9e/factory_test.php index 9ab32999d8..7e35c18332 100644 --- a/tests/text_formatter/s9e/factory_test.php +++ b/tests/text_formatter/s9e/factory_test.php @@ -15,6 +15,16 @@ require_once __DIR__ . '/../../test_framework/phpbb_database_test_case.php'; class phpbb_textformatter_s9e_factory_test extends phpbb_database_test_case { + /** + * @var phpbb_mock_cache + */ + private $cache; + + /** + * @var phpbb_mock_event_dispatcher + */ + private $dispatcher; + protected function setUp(): void { $this->cache = new phpbb_mock_cache; From daa2dd280ca6139e9c50b556814ea2cd825dea64 Mon Sep 17 00:00:00 2001 From: Ruben Calvo Date: Sun, 1 Jan 2023 22:01:52 +0100 Subject: [PATCH 38/42] [ticket/16955] Fix most return types in phpdoc PHPBB3-16955 --- phpBB/includes/acp/acp_attachments.php | 4 +- phpBB/includes/acp/acp_extensions.php | 8 ++-- phpBB/includes/acp/acp_language.php | 2 +- phpBB/includes/acp/acp_storage.php | 4 +- phpBB/includes/bbcode.php | 2 +- phpBB/includes/diff/diff.php | 4 +- phpBB/includes/diff/renderer.php | 2 +- phpBB/includes/functions.php | 41 ++++++++++--------- phpBB/includes/functions_admin.php | 10 +++-- phpBB/includes/functions_compatibility.php | 2 +- phpBB/includes/functions_database_helper.php | 2 +- phpBB/includes/functions_mcp.php | 6 +-- phpBB/includes/functions_messenger.php | 2 + phpBB/includes/functions_posting.php | 5 ++- phpBB/includes/functions_user.php | 7 +++- phpBB/includes/mcp/mcp_queue.php | 6 +-- phpBB/includes/message_parser.php | 2 +- .../includes/questionnaire/questionnaire.php | 2 +- .../install/convertors/functions_phpbb20.php | 2 +- phpBB/install/startup.php | 4 +- .../captcha/plugins/captcha_abstract.php | 2 +- phpBB/phpbb/config/db_text.php | 8 ++-- phpBB/phpbb/config_php_file.php | 2 +- phpBB/phpbb/console/command/cron/run.php | 2 +- .../console/command/extension/install.php | 2 +- .../command/extension/list_available.php | 2 +- .../console/command/extension/manage.php | 2 +- .../console/command/extension/remove.php | 2 +- .../console/command/extension/update.php | 2 +- .../console/command/reparser/list_all.php | 2 +- .../console/command/reparser/reparse.php | 2 +- .../console/command/thumbnail/delete.php | 2 +- .../console/command/thumbnail/generate.php | 2 +- .../console/command/thumbnail/recreate.php | 2 +- phpBB/phpbb/console/command/update/check.php | 2 +- phpBB/phpbb/console/command/user/activate.php | 4 +- phpBB/phpbb/console/command/user/add.php | 6 +-- phpBB/phpbb/console/command/user/delete.php | 2 +- phpBB/phpbb/console/command/user/reclean.php | 2 +- phpBB/phpbb/content_visibility.php | 6 +-- phpBB/phpbb/controller/resolver.php | 2 +- .../phpbb/cron/task/core/prune_all_forums.php | 2 +- phpBB/phpbb/cron/task/core/prune_forum.php | 4 +- phpBB/phpbb/cron/task/core/queue.php | 2 +- phpBB/phpbb/cron/task/core/tidy_cache.php | 2 +- phpBB/phpbb/cron/task/core/tidy_database.php | 2 +- phpBB/phpbb/cron/task/core/tidy_search.php | 2 +- phpBB/phpbb/cron/task/core/tidy_sessions.php | 2 +- phpBB/phpbb/cron/task/core/tidy_warnings.php | 2 +- phpBB/phpbb/db/extractor/mysql_extractor.php | 6 +-- .../migration/profilefield_base_migration.php | 6 +-- phpBB/phpbb/db/migration/tool/config_text.php | 2 +- phpBB/phpbb/db/migrator.php | 2 +- phpBB/phpbb/di/pass/collection_pass.php | 2 +- .../event/kernel_exception_subscriber.php | 2 +- phpBB/phpbb/extension/di/extension_base.php | 1 + phpBB/phpbb/help/controller/help.php | 2 +- phpBB/phpbb/message/form.php | 6 +-- phpBB/phpbb/plupload/plupload.php | 1 + .../report/report_reason_list_provider.php | 2 +- .../default_resources_locator.php | 6 +-- .../search/backend/fulltext_postgres.php | 2 +- phpBB/phpbb/storage/exception/exception.php | 10 ++--- phpBB/phpbb/template/context.php | 4 +- phpBB/phpbb/template/twig/environment.php | 10 ++--- phpBB/phpbb/tree/nestedset.php | 2 +- 66 files changed, 135 insertions(+), 124 deletions(-) diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php index a7e10617fe..0f1fc3f6a8 100644 --- a/phpBB/includes/acp/acp_attachments.php +++ b/phpBB/includes/acp/acp_attachments.php @@ -1349,7 +1349,7 @@ class acp_attachments * Set config attachment stat values * * @param $stats array Array of config key => value pairs to set. - * @return null + * @return void */ public function set_attachment_stats($stats) { @@ -1392,7 +1392,7 @@ class acp_attachments /** * Handle stats resync. * - * @return null + * @return void */ public function handle_stats_resync() { diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 3a29d16ec6..1a30d38d61 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -767,7 +767,7 @@ class acp_extensions * @param \phpbb\extension\manager $phpbb_extension_manager An instance of the extension manager * @param array $managed_packages List of managed packages * - * @return null + * @return void */ public function list_enabled_exts(\phpbb\extension\manager $phpbb_extension_manager, array $managed_packages) { @@ -850,7 +850,7 @@ class acp_extensions * @param \phpbb\extension\manager $phpbb_extension_manager An instance of the extension manager * @param array $managed_packages List of managed packages * - * @return null + * @return void */ public function list_disabled_exts(\phpbb\extension\manager $phpbb_extension_manager, array $managed_packages) { @@ -930,7 +930,7 @@ class acp_extensions * * @param array $managed_packages List of managed packages * - * @return null + * @return void */ public function list_available_exts(array $managed_packages) { @@ -1026,7 +1026,7 @@ class acp_extensions * Outputs extension metadata into the template * * @param array $metadata Array with all metadata for the extension - * @return null + * @return void */ public function output_metadata_to_template($metadata) { diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php index 81b14cc02c..4584be632f 100644 --- a/phpBB/includes/acp/acp_language.php +++ b/phpBB/includes/acp/acp_language.php @@ -224,7 +224,7 @@ class acp_language } catch (\Exception $e) { - return array(); + return; } foreach ($iterator as $file_info) diff --git a/phpBB/includes/acp/acp_storage.php b/phpBB/includes/acp/acp_storage.php index adde39baf3..3ea1036167 100644 --- a/phpBB/includes/acp/acp_storage.php +++ b/phpBB/includes/acp/acp_storage.php @@ -356,8 +356,8 @@ class acp_storage * * @param string $storage_name Storage name * @param array $options Storage provider configuration keys - * @param array $messages Error messages array - * @return array $messages Reference to messages array + * @param array $messages Reference to error messages array + * @return void */ protected function validate_path($storage_name, $options, &$messages) { diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index 736c680316..68621b4245 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -658,7 +658,7 @@ class bbcode * * Accepts variable number of parameters * - * @return mixed Second pass result + * @return bool Second pass result * * @deprecated 3.2.10 (To be removed 4.0.0) */ diff --git a/phpBB/includes/diff/diff.php b/phpBB/includes/diff/diff.php index 8b7d71020a..7c92d37570 100644 --- a/phpBB/includes/diff/diff.php +++ b/phpBB/includes/diff/diff.php @@ -544,7 +544,7 @@ class diff3 extends diff * @param string $label2 the cvs file version/label from the new set of lines * @param string $label_sep the explanation between label1 and label2 - more of a helper for the user * - * @return mixed the merged output + * @return array the merged output */ function get_conflicts_content($label1 = 'CURRENT_FILE', $label2 = 'NEW_FILE', $label_sep = 'DIFF_SEP_EXPLAIN') { @@ -582,7 +582,7 @@ class diff3 extends diff /** * Return merged output (used by the renderer) * - * @return mixed the merged output + * @return array the merged output */ function merged_output() { diff --git a/phpBB/includes/diff/renderer.php b/phpBB/includes/diff/renderer.php index 0c8438ff17..4f00fccfe8 100644 --- a/phpBB/includes/diff/renderer.php +++ b/phpBB/includes/diff/renderer.php @@ -793,7 +793,7 @@ class diff_renderer_side_by_side extends diff_renderer { if ($this->state == 'empty') { - return ''; + return; } // This is just an addition line. diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 58c142c740..27ead08d9c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -115,14 +115,14 @@ function phpbb_gmgetdate($time = false) /** * Return formatted string for filesizes * -* @param mixed $value filesize in bytes +* @param mixed $value filesize in bytes * (non-negative number; int, float or string) -* @param bool $string_only true if language string should be returned -* @param array $allowed_units only allow these units (data array indexes) +* @param bool $string_only true if language string should be returned +* @param array|null $allowed_units only allow these units (data array indexes) * -* @return mixed data array if $string_only is false +* @return array|string data array if $string_only is false */ -function get_formatted_filesize($value, $string_only = true, $allowed_units = false) +function get_formatted_filesize($value, bool $string_only = true, array $allowed_units = null) { global $user; @@ -161,7 +161,7 @@ function get_formatted_filesize($value, $string_only = true, $allowed_units = fa foreach ($available_units as $si_identifier => $unit_info) { - if (!empty($allowed_units) && $si_identifier != 'b' && !in_array($si_identifier, $allowed_units)) + if (is_array($allowed_units) && $si_identifier != 'b' && !in_array($si_identifier, $allowed_units)) { continue; } @@ -238,14 +238,14 @@ function still_on_time($extra_time = 15) * * See http://www.php.net/manual/en/function.version-compare.php * -* @param string $version1 First version number -* @param string $version2 Second version number -* @param string $operator Comparison operator (optional) +* @param string $version1 First version number +* @param string $version2 Second version number +* @param string|null $operator Comparison operator (optional) * -* @return mixed Boolean (true, false) if comparison operator is specified. -* Integer (-1, 0, 1) otherwise. +* @return mixed Boolean (true, false) if comparison operator is specified. +* Integer (-1, 0, 1) otherwise. */ -function phpbb_version_compare($version1, $version2, $operator = null) +function phpbb_version_compare(string $version1, string $version2, string $operator = null) { $version1 = strtolower($version1); $version2 = strtolower($version2); @@ -447,7 +447,7 @@ function phpbb_get_timezone_identifiers($selected_timezone) * @param string $default A timezone to select * @param boolean $truncate Shall we truncate the options text * -* @return array Returns an array containing the options for the time selector. +* @return string Returns an array containing the options for the time selector. */ function phpbb_timezone_select($template, $user, $default = '', $truncate = false) { @@ -1908,7 +1908,7 @@ function meta_refresh($time, $url, $disable_cd_check = false) * * @param int $code HTTP status code * @param string $message Message for the status code -* @return null +* @return void */ function send_status_line($code, $message) { @@ -2893,8 +2893,8 @@ function short_ipv6($ip, $length) * * @param string $address IP address * -* @return mixed false if specified address is not valid, -* string otherwise +* @return string|false false if specified address is not valid, +* string otherwise */ function phpbb_ip_normalise(string $address) { @@ -2922,8 +2922,9 @@ function phpbb_ip_normalise(string $address) /** * Error and message handler, call with trigger_error if read +* @return bool true to bypass internal error handler, false otherwise */ -function msg_handler($errno, $msg_text, $errfile, $errline) +function msg_handler($errno, $msg_text, $errfile, $errline): bool { global $cache, $db, $auth, $template, $config, $user, $request; global $phpbb_root_path, $msg_title, $msg_long_text, $phpbb_log; @@ -2932,7 +2933,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) // Do not display notices if we suppress them via @ if (error_reporting() == 0 && $errno != E_USER_ERROR && $errno != E_USER_WARNING && $errno != E_USER_NOTICE) { - return; + return true; } // Message handler is stripping text. In case we need it, we are possible to define long text... @@ -2950,7 +2951,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) // If DEBUG is defined the default level is E_ALL if (($errno & ($phpbb_container != null && $phpbb_container->getParameter('debug.show_errors') ? E_ALL : error_reporting())) == 0) { - return; + return true; } if (strpos($errfile, 'cache') === false && strpos($errfile, 'template.') === false) @@ -2968,7 +2969,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) // echo '

BACKTRACE
' . get_backtrace() . '
' . "\n"; } - return; + return true; break; diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 54ba46fb67..621d1a284e 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -761,6 +761,7 @@ function move_posts($post_ids, $topic_id, $auto_sync = true) /** * Remove topic(s) +* @return array with topics and posts affected */ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_sync = true, $call_delete_posts = true) { @@ -1202,7 +1203,7 @@ function delete_topic_shadows($forum_id, $sql_more = '', $auto_sync = true) if (!$forum_id) { // Nothing to do. - return; + return []; } // Set of affected forums we have to resync @@ -2325,6 +2326,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, /** * Prune function +* @return array with topics and posts affected */ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync = true, $prune_limit = 0) { @@ -2337,7 +2339,7 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync if (!count($forum_id)) { - return; + return ['topics' => 0, 'posts' => 0]; } $sql_and = ''; @@ -2697,7 +2699,7 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id * @param \phpbb\auth\auth $auth Authentication object * @param array|bool $group_id If an array, remove all members of this group from foe lists, or false to ignore * @param array|bool $user_id If an array, remove this user from foe lists, or false to ignore -* @return null +* @return void */ function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false) { @@ -3116,7 +3118,7 @@ function add_permission_language() * @param int $flag The binary flag which is OR-ed with the current column value * @param string $sql_more This string is attached to the sql query generated to update the table. * - * @return null + * @return void */ function enable_bitfield_column_flag($table_name, $column_name, $flag, $sql_more = '') { diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php index dd56aa9622..5ecd8c7a37 100644 --- a/phpBB/includes/functions_compatibility.php +++ b/phpBB/includes/functions_compatibility.php @@ -136,7 +136,7 @@ function cache_moderators() * @deprecated 3.1.0 (To be removed: 4.0.0) * @param array|bool $group_id If an array, remove all members of this group from foe lists, or false to ignore * @param array|bool $user_id If an array, remove this user from foe lists, or false to ignore -* @return null +* @return void */ function update_foes($group_id = false, $user_id = false) { diff --git a/phpBB/includes/functions_database_helper.php b/phpBB/includes/functions_database_helper.php index 8f363d56f3..268cb2f384 100644 --- a/phpBB/includes/functions_database_helper.php +++ b/phpBB/includes/functions_database_helper.php @@ -31,7 +31,7 @@ if (!defined('IN_PHPBB')) * @param string $column Column whose values to change * @param array $from_values An array of values that should be changed * @param int $to_value The new value -* @return null +* @return void */ function phpbb_update_rows_avoiding_duplicates(\phpbb\db\driver\driver_interface $db, $table, $column, $from_values, $to_value) { diff --git a/phpBB/includes/functions_mcp.php b/phpBB/includes/functions_mcp.php index e96f193370..c09eeeaeb5 100644 --- a/phpBB/includes/functions_mcp.php +++ b/phpBB/includes/functions_mcp.php @@ -695,9 +695,9 @@ function phpbb_mcp_sorting($mode, &$sort_days_val, &$sort_key_val, &$sort_dir_va * @param array|false $acl_list A list of permissions the user need to have * @param mixed $single_forum Limit to one forum id (int) or the first forum found (true) * -* @return mixed False if no ids were able to be retrieved, true if at least one id left. -* Additionally, this value can be the forum_id assigned if $single_forum was set. -* Therefore checking the result for with !== false is the best method. +* @return bool|int False if no ids were able to be retrieved, true if at least one id left. +* Additionally, this value can be the forum_id assigned if $single_forum was set. +* Therefore checking the result for with !== false is the best method. */ function phpbb_check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = false) { diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 376b98f338..e5cc4ac641 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -1570,6 +1570,8 @@ class smtp_class unset($response[0]); $this->commands[$response_code] = implode(' ', $response); } + + return null; } /** diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 80f0e31e74..6e4806a93a 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -253,6 +253,7 @@ function generate_smilies($mode, $forum_id) * @param string $type Can be forum|topic * @param mixed $ids topic/forum ids * @param bool $return_update_sql true: SQL query shall be returned, false: execute SQL +* @return array|null SQL query, null otherwise */ function update_post_information($type, $ids, $return_update_sql = false) { @@ -412,7 +413,7 @@ function update_post_information($type, $ids, $return_update_sql = false) $db->sql_query($sql); } - return; + return null; } /** @@ -2780,7 +2781,7 @@ function phpbb_upload_popup($forum_style = 0) * @param bool $is_soft The flag indicating whether it is the soft delete mode * @param string $delete_reason Description for the post deletion reason * -* @return null +* @return void */ function phpbb_handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_soft = false, $delete_reason = '') { diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 905a7a8251..9cdeb7c619 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1727,7 +1727,7 @@ function phpbb_validate_timezone($timezone) * @param string $username The username to check * @param string $allowed_username An allowed username, default being $user->data['username'] * - * @return mixed Either false if validation succeeded or a string which will be + * @return string|false Either false if validation succeeded or a string which will be * used as the error message (with the variable name appended) */ function validate_username($username, $allowed_username = false, $allow_all_names = false) @@ -2723,7 +2723,7 @@ function group_delete($group_id, $group_name = false) /** * Add user(s) to group * -* @return mixed false if no errors occurred, else the user lang string for the relevant error, for example 'NO_USER' +* @return string|false false if no errors occurred, else the user lang string for the relevant error, for example 'NO_USER' */ function group_user_add($group_id, $user_id_ary = false, $username_ary = false, $group_name = false, $default = false, $leader = 0, $pending = 0, $group_attributes = false) { @@ -3073,6 +3073,7 @@ function remove_default_avatar($group_id, $user_ids) /** * Removes the group rank of the default group from the users in user_ids who have that group as default. +* @return bool true if successful, false if not */ function remove_default_rank($group_id, $user_ids) { @@ -3107,6 +3108,8 @@ function remove_default_rank($group_id, $user_ids) AND user_rank = ' . (int) $row['group_rank'] . ' AND ' . $db->sql_in_set('user_id', $user_ids); $db->sql_query($sql); + + return true; } /** diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index de3794353f..185316a705 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -677,7 +677,7 @@ class mcp_queue * @param $post_id_list array IDs of the posts to approve/restore * @param $id mixed Category of the current active module * @param $mode string Active module - * @return null + * @return void|never */ public static function approve_posts($action, $post_id_list, $id, $mode) { @@ -937,7 +937,7 @@ class mcp_queue * @param $topic_id_list array IDs of the topics to approve/restore * @param $id mixed Category of the current active module * @param $mode string Active module - * @return null + * @return void|never */ public static function approve_topics($action, $topic_id_list, $id, $mode) { @@ -1136,7 +1136,7 @@ class mcp_queue * @param $post_id_list array IDs of the posts to disapprove/delete * @param $id mixed Category of the current active module * @param $mode string Active module - * @return null + * @return void|never */ public static function disapprove_posts($post_id_list, $id, $mode) { diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 8257a895c5..7e856858ad 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1902,7 +1902,7 @@ class parse_message extends bbcode_firstpass * Remove nested quotes at given depth in current parsed message * * @param integer $max_depth Depth limit - * @return null + * @return void */ public function remove_nested_quotes($max_depth) { diff --git a/phpBB/includes/questionnaire/questionnaire.php b/phpBB/includes/questionnaire/questionnaire.php index 08fee2e1ae..8ab18ad8c8 100644 --- a/phpBB/includes/questionnaire/questionnaire.php +++ b/phpBB/includes/questionnaire/questionnaire.php @@ -74,7 +74,7 @@ class phpbb_questionnaire_data_collector /** * Collect info into the data property. * - * @return null + * @return void */ function collect() { diff --git a/phpBB/install/convertors/functions_phpbb20.php b/phpBB/install/convertors/functions_phpbb20.php index aed6c3aece..75a0b8def4 100644 --- a/phpBB/install/convertors/functions_phpbb20.php +++ b/phpBB/install/convertors/functions_phpbb20.php @@ -1317,7 +1317,7 @@ function phpbb_get_files_dir() { if (!defined('MOD_ATTACHMENT')) { - return; + return ''; } global $src_db, $same_db, $convert, $user; diff --git a/phpBB/install/startup.php b/phpBB/install/startup.php index 0aaa9a648f..4e012216a6 100644 --- a/phpBB/install/startup.php +++ b/phpBB/install/startup.php @@ -47,7 +47,7 @@ function phpbb_include_updated($path, $phpbb_root_path, $optional = false) } } -function installer_msg_handler($errno, $msg_text, $errfile, $errline) +function installer_msg_handler($errno, $msg_text, $errfile, $errline): bool { global $phpbb_installer_container, $msg_long_text; @@ -88,7 +88,7 @@ function installer_msg_handler($errno, $msg_text, $errfile, $errline) print($msg); } - return; + return false; break; case E_USER_ERROR: $msg = 'General Error:
' . $msg_text . '
in file ' . $errfile . ' on line ' . $errline . '

'; diff --git a/phpBB/phpbb/captcha/plugins/captcha_abstract.php b/phpBB/phpbb/captcha/plugins/captcha_abstract.php index dd1f9f1c48..012e28c987 100644 --- a/phpBB/phpbb/captcha/plugins/captcha_abstract.php +++ b/phpBB/phpbb/captcha/plugins/captcha_abstract.php @@ -75,7 +75,7 @@ abstract class captcha_abstract if (!$this->load_code()) { // invalid request, bail out - return false; + return; } } $generator = $this->get_generator_class(); diff --git a/phpBB/phpbb/config/db_text.php b/phpBB/phpbb/config/db_text.php index 818f6bdcc9..136158cc98 100644 --- a/phpBB/phpbb/config/db_text.php +++ b/phpBB/phpbb/config/db_text.php @@ -48,7 +48,7 @@ class db_text * @param string $key The configuration option's name * @param string $value New configuration value * - * @return null + * @return void */ public function set($key, $value) { @@ -75,7 +75,7 @@ class db_text * * @param string $key The configuration option's name * - * @return null + * @return void */ public function delete($key) { @@ -89,7 +89,7 @@ class db_text * * @param array $map Map from configuration names to values * - * @return null + * @return void */ public function set_array(array $map) { @@ -147,7 +147,7 @@ class db_text * * @param array $keys Set of configuration option names * - * @return null + * @return void */ public function delete_array(array $keys) { diff --git a/phpBB/phpbb/config_php_file.php b/phpBB/phpbb/config_php_file.php index e3eeef06f0..77bc1ae5a6 100644 --- a/phpBB/phpbb/config_php_file.php +++ b/phpBB/phpbb/config_php_file.php @@ -94,7 +94,7 @@ class config_php_file /** * Load the config file and store the information. * - * @return null + * @return void */ protected function load_config_file() { diff --git a/phpBB/phpbb/console/command/cron/run.php b/phpBB/phpbb/console/command/cron/run.php index e105911511..d31abb0691 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -45,7 +45,7 @@ class run extends \phpbb\console\command\command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/extension/install.php b/phpBB/phpbb/console/command/extension/install.php index 0e59abd212..1f414e348e 100644 --- a/phpBB/phpbb/console/command/extension/install.php +++ b/phpBB/phpbb/console/command/extension/install.php @@ -49,7 +49,7 @@ class install extends \phpbb\console\command\command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/extension/list_available.php b/phpBB/phpbb/console/command/extension/list_available.php index 1c38b8922f..c53f83c7c7 100644 --- a/phpBB/phpbb/console/command/extension/list_available.php +++ b/phpBB/phpbb/console/command/extension/list_available.php @@ -38,7 +38,7 @@ class list_available extends \phpbb\console\command\command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/extension/manage.php b/phpBB/phpbb/console/command/extension/manage.php index cb97c6d141..393488e6af 100644 --- a/phpBB/phpbb/console/command/extension/manage.php +++ b/phpBB/phpbb/console/command/extension/manage.php @@ -48,7 +48,7 @@ class manage extends \phpbb\console\command\command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/extension/remove.php b/phpBB/phpbb/console/command/extension/remove.php index 629d55a7a9..9197caed0b 100644 --- a/phpBB/phpbb/console/command/extension/remove.php +++ b/phpBB/phpbb/console/command/extension/remove.php @@ -49,7 +49,7 @@ class remove extends \phpbb\console\command\command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/extension/update.php b/phpBB/phpbb/console/command/extension/update.php index 8992b48241..d469d967e4 100644 --- a/phpBB/phpbb/console/command/extension/update.php +++ b/phpBB/phpbb/console/command/extension/update.php @@ -46,7 +46,7 @@ class update extends \phpbb\console\command\command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php index 83c301e00f..a062fac75a 100644 --- a/phpBB/phpbb/console/command/reparser/list_all.php +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -45,7 +45,7 @@ class list_all extends \phpbb\console\command\command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 529035233d..1e66a22a73 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -79,7 +79,7 @@ class reparse extends \phpbb\console\command\command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 1fca707eed..21fb843e7d 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -55,7 +55,7 @@ class delete extends \phpbb\console\command\command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index ac70a2d92e..9be4ce5a2e 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -72,7 +72,7 @@ class generate extends \phpbb\console\command\command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index bea7a33d87..cffa2c29dc 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -22,7 +22,7 @@ class recreate extends \phpbb\console\command\command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index bb9114652a..74220394e2 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -57,7 +57,7 @@ class check extends \phpbb\console\command\command * * Sets the name and description of the command. * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/user/activate.php b/phpBB/phpbb/console/command/user/activate.php index 35835eed5d..1d635b46dc 100644 --- a/phpBB/phpbb/console/command/user/activate.php +++ b/phpBB/phpbb/console/command/user/activate.php @@ -87,7 +87,7 @@ class activate extends command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { @@ -186,7 +186,7 @@ class activate extends command * * @param array $user_row The user data array * @param InputInterface $input The input stream used to get the options - * @return null + * @return void */ protected function send_notification($user_row, InputInterface $input) { diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index fb4ffd5ffb..d26007dfb5 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -85,7 +85,7 @@ class add extends command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { @@ -226,7 +226,7 @@ class add extends command * Validate the submitted user data * * @throws runtime_exception if any data fails validation - * @return null + * @return void */ protected function validate_user_data() { @@ -283,7 +283,7 @@ class add extends command * Send account activation email * * @param int $user_id The new user's id - * @return null + * @return void */ protected function send_activation_email($user_id) { diff --git a/phpBB/phpbb/console/command/user/delete.php b/phpBB/phpbb/console/command/user/delete.php index abda29fedf..acd360b57b 100644 --- a/phpBB/phpbb/console/command/user/delete.php +++ b/phpBB/phpbb/console/command/user/delete.php @@ -76,7 +76,7 @@ class delete extends command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/console/command/user/reclean.php b/phpBB/phpbb/console/command/user/reclean.php index 6ad5ac4f92..96932fcdaa 100644 --- a/phpBB/phpbb/console/command/user/reclean.php +++ b/phpBB/phpbb/console/command/user/reclean.php @@ -55,7 +55,7 @@ class reclean extends command /** * Sets the command name and description * - * @return null + * @return void */ protected function configure() { diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index a3b0e378fc..99f89580d7 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -839,7 +839,7 @@ class content_visibility * * @param $data array Contains information from the topics table about given topic * @param $sql_data array Populated with the SQL changes, may be empty at call time (by reference) - * @return null + * @return void */ public function add_post_to_statistic($data, &$sql_data) { @@ -860,7 +860,7 @@ class content_visibility * * @param $data array Contains information from the topics table about given topic * @param $sql_data array Populated with the SQL changes, may be empty at call time (by reference) - * @return null + * @return void */ public function remove_post_from_statistic($data, &$sql_data) { @@ -893,7 +893,7 @@ class content_visibility * * @param $data array Post and topic data * @param $sql_data array Populated with the SQL changes, may be empty at call time (by reference) - * @return null + * @return void */ public function remove_topic_from_statistic($data, &$sql_data) { diff --git a/phpBB/phpbb/controller/resolver.php b/phpBB/phpbb/controller/resolver.php index 943bd570d1..1e65b2324b 100644 --- a/phpBB/phpbb/controller/resolver.php +++ b/phpBB/phpbb/controller/resolver.php @@ -65,7 +65,7 @@ class resolver implements ControllerResolverInterface * Load a controller callable * * @param Request $request Symfony Request object - * @return bool|Callable Callable or false + * @return false|Callable Callable or false (fixme: method is returning an array) * @throws \phpbb\controller\exception */ public function getController(Request $request) diff --git a/phpBB/phpbb/cron/task/core/prune_all_forums.php b/phpBB/phpbb/cron/task/core/prune_all_forums.php index 664e37b1a1..d7d8d4fd9a 100644 --- a/phpBB/phpbb/cron/task/core/prune_all_forums.php +++ b/phpBB/phpbb/cron/task/core/prune_all_forums.php @@ -46,7 +46,7 @@ class prune_all_forums extends \phpbb\cron\task\base /** * Runs this cron task. * - * @return null + * @return void */ public function run() { diff --git a/phpBB/phpbb/cron/task/core/prune_forum.php b/phpBB/phpbb/cron/task/core/prune_forum.php index 2060babc25..3e32c67283 100644 --- a/phpBB/phpbb/cron/task/core/prune_forum.php +++ b/phpBB/phpbb/cron/task/core/prune_forum.php @@ -66,7 +66,7 @@ class prune_forum extends \phpbb\cron\task\base implements \phpbb\cron\task\para /** * Runs this cron task. * - * @return null + * @return void */ public function run() { @@ -137,7 +137,7 @@ class prune_forum extends \phpbb\cron\task\base implements \phpbb\cron\task\para * * @param \phpbb\request\request_interface $request Request object. * - * @return null + * @return void */ public function parse_parameters(\phpbb\request\request_interface $request) { diff --git a/phpBB/phpbb/cron/task/core/queue.php b/phpBB/phpbb/cron/task/core/queue.php index eca69a5041..2f0d91d046 100644 --- a/phpBB/phpbb/cron/task/core/queue.php +++ b/phpBB/phpbb/cron/task/core/queue.php @@ -42,7 +42,7 @@ class queue extends \phpbb\cron\task\base /** * Runs this cron task. * - * @return null + * @return void */ public function run() { diff --git a/phpBB/phpbb/cron/task/core/tidy_cache.php b/phpBB/phpbb/cron/task/core/tidy_cache.php index 506a245f0f..514974e6c8 100644 --- a/phpBB/phpbb/cron/task/core/tidy_cache.php +++ b/phpBB/phpbb/cron/task/core/tidy_cache.php @@ -36,7 +36,7 @@ class tidy_cache extends \phpbb\cron\task\base /** * Runs this cron task. * - * @return null + * @return void */ public function run() { diff --git a/phpBB/phpbb/cron/task/core/tidy_database.php b/phpBB/phpbb/cron/task/core/tidy_database.php index 949bba8012..51fb26cda2 100644 --- a/phpBB/phpbb/cron/task/core/tidy_database.php +++ b/phpBB/phpbb/cron/task/core/tidy_database.php @@ -39,7 +39,7 @@ class tidy_database extends \phpbb\cron\task\base /** * Runs this cron task. * - * @return null + * @return void */ public function run() { diff --git a/phpBB/phpbb/cron/task/core/tidy_search.php b/phpBB/phpbb/cron/task/core/tidy_search.php index a29a403627..ba038a1048 100644 --- a/phpBB/phpbb/cron/task/core/tidy_search.php +++ b/phpBB/phpbb/cron/task/core/tidy_search.php @@ -59,7 +59,7 @@ class tidy_search extends base /** * Runs this cron task. * - * @return null + * @return void */ public function run() { diff --git a/phpBB/phpbb/cron/task/core/tidy_sessions.php b/phpBB/phpbb/cron/task/core/tidy_sessions.php index 5e6dabdabf..78c99e8be0 100644 --- a/phpBB/phpbb/cron/task/core/tidy_sessions.php +++ b/phpBB/phpbb/cron/task/core/tidy_sessions.php @@ -36,7 +36,7 @@ class tidy_sessions extends \phpbb\cron\task\base /** * Runs this cron task. * - * @return null + * @return void */ public function run() { diff --git a/phpBB/phpbb/cron/task/core/tidy_warnings.php b/phpBB/phpbb/cron/task/core/tidy_warnings.php index 7b67eae6ef..b9dda21012 100644 --- a/phpBB/phpbb/cron/task/core/tidy_warnings.php +++ b/phpBB/phpbb/cron/task/core/tidy_warnings.php @@ -41,7 +41,7 @@ class tidy_warnings extends \phpbb\cron\task\base /** * Runs this cron task. * - * @return null + * @return void */ public function run() { diff --git a/phpBB/phpbb/db/extractor/mysql_extractor.php b/phpBB/phpbb/db/extractor/mysql_extractor.php index 6d230a6e35..386130e4ae 100644 --- a/phpBB/phpbb/db/extractor/mysql_extractor.php +++ b/phpBB/phpbb/db/extractor/mysql_extractor.php @@ -86,7 +86,7 @@ class mysql_extractor extends base_extractor * Extracts data from database table (for MySQLi driver) * * @param string $table_name name of the database table - * @return null + * @return void * @throws extractor_not_initialized_exception when calling this function before init_extractor() */ protected function write_data_mysqli($table_name) @@ -176,7 +176,7 @@ class mysql_extractor extends base_extractor * Extracts database table structure (for MySQLi or MySQL 3.23.20+) * * @param string $table_name name of the database table - * @return null + * @return void * @throws extractor_not_initialized_exception when calling this function before init_extractor() */ protected function new_write_table($table_name) @@ -201,7 +201,7 @@ class mysql_extractor extends base_extractor * Extracts database table structure (for MySQL versions older than 3.23.20) * * @param string $table_name name of the database table - * @return null + * @return void * @throws extractor_not_initialized_exception when calling this function before init_extractor() */ protected function old_write_table($table_name) diff --git a/phpBB/phpbb/db/migration/profilefield_base_migration.php b/phpBB/phpbb/db/migration/profilefield_base_migration.php index bc542a8fed..9ec0e2bb3e 100644 --- a/phpBB/phpbb/db/migration/profilefield_base_migration.php +++ b/phpBB/phpbb/db/migration/profilefield_base_migration.php @@ -183,8 +183,8 @@ abstract class profilefield_base_migration extends container_aware_migration } /** - * @param int $start Start of staggering step - * @return mixed int start of the next step, null if the end was reached + * @param int $start Start of staggering step + * @return int|null int start of the next step, null if the end was reached */ public function convert_user_field_to_custom_field($start) { @@ -226,7 +226,7 @@ abstract class profilefield_base_migration extends container_aware_migration if ($converted_users < $limit) { // No more users left, we are done... - return; + return null; } return $start + $limit; diff --git a/phpBB/phpbb/db/migration/tool/config_text.php b/phpBB/phpbb/db/migration/tool/config_text.php index 6080619dfa..89fa3b9d71 100644 --- a/phpBB/phpbb/db/migration/tool/config_text.php +++ b/phpBB/phpbb/db/migration/tool/config_text.php @@ -63,7 +63,7 @@ class config_text implements \phpbb\db\migration\tool\tool_interface * @param string $config_name The name of the config_text setting you would * like to update * @param mixed $config_value The value of the config_text setting - * @return null + * @return void * @throws \phpbb\db\migration\exception */ public function update($config_name, $config_value) diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index 60673ea9bc..972c2d5107 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -732,7 +732,7 @@ class migrator if ($callable_and_parameters === false) { - return; + return null; } $callable = $callable_and_parameters[0]; diff --git a/phpBB/phpbb/di/pass/collection_pass.php b/phpBB/phpbb/di/pass/collection_pass.php index 341f88518d..049337d974 100644 --- a/phpBB/phpbb/di/pass/collection_pass.php +++ b/phpBB/phpbb/di/pass/collection_pass.php @@ -27,7 +27,7 @@ class collection_pass implements CompilerPassInterface * Modify the container before it is passed to the rest of the code * * @param ContainerBuilder $container ContainerBuilder object - * @return null + * @return void */ public function process(ContainerBuilder $container) { diff --git a/phpBB/phpbb/event/kernel_exception_subscriber.php b/phpBB/phpbb/event/kernel_exception_subscriber.php index 71959d81e0..4adb3f10ef 100644 --- a/phpBB/phpbb/event/kernel_exception_subscriber.php +++ b/phpBB/phpbb/event/kernel_exception_subscriber.php @@ -66,7 +66,7 @@ class kernel_exception_subscriber implements EventSubscriberInterface * This listener is run when the KernelEvents::EXCEPTION event is triggered * * @param ExceptionEvent $event - * @return null + * @return void */ public function on_kernel_exception(ExceptionEvent $event) { diff --git a/phpBB/phpbb/extension/di/extension_base.php b/phpBB/phpbb/extension/di/extension_base.php index 97033e7ddb..fcc358dd79 100644 --- a/phpBB/phpbb/extension/di/extension_base.php +++ b/phpBB/phpbb/extension/di/extension_base.php @@ -122,6 +122,7 @@ class extension_base extends Extension } } + return null; } /** diff --git a/phpBB/phpbb/help/controller/help.php b/phpBB/phpbb/help/controller/help.php index 3bf6fe3098..557b564da4 100644 --- a/phpBB/phpbb/help/controller/help.php +++ b/phpBB/phpbb/help/controller/help.php @@ -124,7 +124,7 @@ class help * Assigns the help data to the template blocks * * @param array $help_data - * @return null + * @return void */ protected function assign_to_template(array $help_data) { diff --git a/phpBB/phpbb/message/form.php b/phpBB/phpbb/message/form.php index 6573a04f8b..c23b168906 100644 --- a/phpBB/phpbb/message/form.php +++ b/phpBB/phpbb/message/form.php @@ -118,7 +118,7 @@ abstract class form * Bind the values of the request to the form * * @param \phpbb\request\request_interface $request - * @return null + * @return void */ public function bind(\phpbb\request\request_interface $request) { @@ -130,7 +130,7 @@ abstract class form * Submit form, generate the email and send it * * @param \messenger $messenger - * @return null + * @return void */ public function submit(\messenger $messenger) { @@ -162,7 +162,7 @@ abstract class form * Render the template of the form * * @param \phpbb\template\template $template - * @return null + * @return void */ public function render(\phpbb\template\template $template) { diff --git a/phpBB/phpbb/plupload/plupload.php b/phpBB/phpbb/plupload/plupload.php index aeb1bd87d2..6ccb141313 100644 --- a/phpBB/phpbb/plupload/plupload.php +++ b/phpBB/phpbb/plupload/plupload.php @@ -138,6 +138,7 @@ class plupload 'id' => 'id', 'result' => null, )); + return null; } } diff --git a/phpBB/phpbb/report/report_reason_list_provider.php b/phpBB/phpbb/report/report_reason_list_provider.php index 388a61d577..6d9bd7694e 100644 --- a/phpBB/phpbb/report/report_reason_list_provider.php +++ b/phpBB/phpbb/report/report_reason_list_provider.php @@ -48,7 +48,7 @@ class report_reason_list_provider * Sets template variables to render report reasons select HTML input * * @param int $reason_id - * @return null + * @return void */ public function display_reasons($reason_id = 0) { diff --git a/phpBB/phpbb/routing/resources_locator/default_resources_locator.php b/phpBB/phpbb/routing/resources_locator/default_resources_locator.php index 90c3877007..8cbf089b2a 100644 --- a/phpBB/phpbb/routing/resources_locator/default_resources_locator.php +++ b/phpBB/phpbb/routing/resources_locator/default_resources_locator.php @@ -44,9 +44,9 @@ class default_resources_locator implements resources_locator_interface /** * Construct method * - * @param string $phpbb_root_path phpBB root path - * @param string $environment Name of the current environment - * @param manager $extension_manager Extension manager + * @param string $phpbb_root_path phpBB root path + * @param string $environment Name of the current environment + * @param manager|null $extension_manager Extension manager */ public function __construct($phpbb_root_path, $environment, manager $extension_manager = null) { diff --git a/phpBB/phpbb/search/backend/fulltext_postgres.php b/phpBB/phpbb/search/backend/fulltext_postgres.php index efd6ecc148..6c4ac05932 100644 --- a/phpBB/phpbb/search/backend/fulltext_postgres.php +++ b/phpBB/phpbb/search/backend/fulltext_postgres.php @@ -1011,7 +1011,7 @@ class fulltext_postgres extends base implements search_backend_interface } /** - * {@inheritdoc} + * Computes the stats and store them in the $this->stats associative array */ protected function get_stats() { diff --git a/phpBB/phpbb/storage/exception/exception.php b/phpBB/phpbb/storage/exception/exception.php index 3a587bea3f..8268530c16 100644 --- a/phpBB/phpbb/storage/exception/exception.php +++ b/phpBB/phpbb/storage/exception/exception.php @@ -20,11 +20,11 @@ class exception extends runtime_exception /** * Constructor * - * @param string $message The Exception message to throw (must be a language variable) - * @param string $filename The file that caused the error - * @param array $parameters The parameters to use with the language var - * @param \Exception $previous The previous runtime_exception used for the runtime_exception chaining - * @param integer $code The Exception code + * @param string $message The Exception message to throw (must be a language variable) + * @param string $filename The file that caused the error + * @param array $parameters The parameters to use with the language var + * @param \Exception|null $previous The previous runtime_exception used for the runtime_exception chaining + * @param integer $code The Exception code */ public function __construct($message = '', $filename = '', $parameters = [], \Exception $previous = null, $code = 0) { diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index d98d8b6e28..7f83152590 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -340,7 +340,7 @@ class context * If key is false the position is set to 0 * If key is true the position is set to the last entry * - * @return mixed false if not found, index position otherwise; be sure to test with === + * @return false|int false if not found, index position otherwise; be sure to test with === */ public function find_key_index($blockname, $key) { @@ -377,7 +377,7 @@ class context // Change key to zero (change first position) if false and to last position if true if (is_bool($key)) { - return (!$key) ? 0 : count($block) - 1; + return (!$key) ? 0 : (count($block) ?? 0) - 1; } // Get correct position if array given diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index bcffbd06ce..5843cc0762 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -54,9 +54,9 @@ class environment extends \Twig\Environment * @param \phpbb\filesystem\filesystem $filesystem * @param \phpbb\path_helper $path_helper phpBB path helper * @param string $cache_path The path to the cache directory - * @param \phpbb\extension\manager $extension_manager phpBB extension manager - * @param \Twig\Loader\LoaderInterface $loader Twig loader interface - * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object + * @param \phpbb\extension\manager|null $extension_manager phpBB extension manager + * @param \Twig\Loader\LoaderInterface|null $loader Twig loader interface + * @param \phpbb\event\dispatcher_interface|null $phpbb_dispatcher Event dispatcher object * @param array $options Array of options to pass to Twig */ public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig\Loader\LoaderInterface $loader = null, \phpbb\event\dispatcher_interface $phpbb_dispatcher = null, $options = array()) @@ -195,7 +195,7 @@ class environment extends \Twig\Environment } /** - * {@inheritdoc} + * Get template with assets */ private function display_with_assets($name, array $context = []) { @@ -261,7 +261,7 @@ class environment extends \Twig\Environment * * @param string $cls The template class associated with the given template name * @param string $name The template name - * @param integer $index The index if it is an embedded template + * @param integer|null $index The index if it is an embedded template * @return \Twig\Template A template instance representing the given template name * @throws \Twig\Error\LoaderError */ diff --git a/phpBB/phpbb/tree/nestedset.php b/phpBB/phpbb/tree/nestedset.php index b25a91b7b9..3a32710ebc 100644 --- a/phpBB/phpbb/tree/nestedset.php +++ b/phpBB/phpbb/tree/nestedset.php @@ -700,7 +700,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface * @param bool $set_subset_zero Should the parent, left and right id of the items be set to 0, or kept unchanged? * In case of removing an item from the tree, we should the values to 0 * In case of moving an item, we shouldkeep the original values, in order to allow "+ diff" later - * @return null + * @return void */ protected function remove_subset(array $subset_items, array $bounding_item, $set_subset_zero = true) { From 4d6dbfb745e836d4a1fd65dab7ad8b133ee547b2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 2 Jan 2023 22:08:36 +0100 Subject: [PATCH 39/42] [ticket/16955] Move iterators to finder folder PHPBB3-16955 --- .../{iterator => finder}/recursive_dot_prefix_filter_iterator.php | 0 phpBB/phpbb/{iterator => finder}/recursive_path_iterator.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename phpBB/phpbb/{iterator => finder}/recursive_dot_prefix_filter_iterator.php (100%) rename phpBB/phpbb/{iterator => finder}/recursive_path_iterator.php (100%) diff --git a/phpBB/phpbb/iterator/recursive_dot_prefix_filter_iterator.php b/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php similarity index 100% rename from phpBB/phpbb/iterator/recursive_dot_prefix_filter_iterator.php rename to phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php diff --git a/phpBB/phpbb/iterator/recursive_path_iterator.php b/phpBB/phpbb/finder/recursive_path_iterator.php similarity index 100% rename from phpBB/phpbb/iterator/recursive_path_iterator.php rename to phpBB/phpbb/finder/recursive_path_iterator.php From a366eb7f6c08587546ea329755015ba74d654aef Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 2 Jan 2023 22:10:50 +0100 Subject: [PATCH 40/42] [ticket/16955] Update namespace for iterators to finder PHPBB3-16955 --- phpBB/includes/acp/acp_language.php | 2 +- phpBB/includes/functions_compatibility.php | 2 +- phpBB/phpbb/event/md_exporter.php | 2 +- phpBB/phpbb/extension/manager.php | 2 +- phpBB/phpbb/finder/finder.php | 2 +- phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php | 2 +- phpBB/phpbb/finder/recursive_path_iterator.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php index 4584be632f..6f95a8df2b 100644 --- a/phpBB/includes/acp/acp_language.php +++ b/phpBB/includes/acp/acp_language.php @@ -220,7 +220,7 @@ class acp_language { try { - $iterator = new \phpbb\iterator\recursive_path_iterator($this->phpbb_root_path . 'language/' . $this->config['default_lang'] . '/'); + $iterator = new \phpbb\finder\recursive_path_iterator($this->phpbb_root_path . 'language/' . $this->config['default_lang'] . '/'); } catch (\Exception $e) { diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php index 5ecd8c7a37..77b2ef4220 100644 --- a/phpBB/includes/functions_compatibility.php +++ b/phpBB/includes/functions_compatibility.php @@ -646,7 +646,7 @@ function phpbb_email_hash($email) */ function phpbb_load_extensions_autoloaders($phpbb_root_path) { - $iterator = new \phpbb\iterator\recursive_path_iterator( + $iterator = new \phpbb\finder\recursive_path_iterator( $phpbb_root_path . 'ext/', \RecursiveIteratorIterator::SELF_FIRST, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index fcc5b78afc..04e5f91ca2 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -659,7 +659,7 @@ class md_exporter { try { - $iterator = new \phpbb\iterator\recursive_path_iterator( + $iterator = new \phpbb\finder\recursive_path_iterator( $dir, \RecursiveIteratorIterator::SELF_FIRST ); diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 24dfeb75b4..adb6d884d1 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -380,7 +380,7 @@ class manager return $available; } - $iterator = new \phpbb\iterator\recursive_path_iterator( + $iterator = new \phpbb\finder\recursive_path_iterator( $this->phpbb_root_path . 'ext/', \RecursiveIteratorIterator::SELF_FIRST, \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::FOLLOW_SYMLINKS diff --git a/phpBB/phpbb/finder/finder.php b/phpBB/phpbb/finder/finder.php index bcd1c355c0..9e7f201ea3 100644 --- a/phpBB/phpbb/finder/finder.php +++ b/phpBB/phpbb/finder/finder.php @@ -486,7 +486,7 @@ class finder if (is_dir($path)) { - $iterator = new \phpbb\iterator\recursive_path_iterator( + $iterator = new \phpbb\finder\recursive_path_iterator( $path, \RecursiveIteratorIterator::SELF_FIRST ); diff --git a/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php b/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php index 08f5bde262..e4f9ea1d8a 100644 --- a/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php +++ b/phpBB/phpbb/finder/recursive_dot_prefix_filter_iterator.php @@ -11,7 +11,7 @@ * */ -namespace phpbb\iterator; +namespace phpbb\finder; /** * Class recursive_dot_prefix_filter_iterator diff --git a/phpBB/phpbb/finder/recursive_path_iterator.php b/phpBB/phpbb/finder/recursive_path_iterator.php index d120c451fd..f93a240af2 100644 --- a/phpBB/phpbb/finder/recursive_path_iterator.php +++ b/phpBB/phpbb/finder/recursive_path_iterator.php @@ -13,7 +13,7 @@ declare(strict_types=1); -namespace phpbb\iterator; +namespace phpbb\finder; class recursive_path_iterator extends \RecursiveIteratorIterator { From daa6d2240c6ea733f91f1a7fee4313181d2de11a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 2 Jan 2023 22:12:58 +0100 Subject: [PATCH 41/42] [ticket/16955] Cache ttl is always integer value PHPBB3-16955 --- phpBB/phpbb/mention/source/base_group.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/mention/source/base_group.php b/phpBB/phpbb/mention/source/base_group.php index 58fca4d054..d9b3699f10 100644 --- a/phpBB/phpbb/mention/source/base_group.php +++ b/phpBB/phpbb/mention/source/base_group.php @@ -41,8 +41,8 @@ abstract class base_group implements source_interface /** @var string */ protected $php_ext; - /** @var string|false */ - protected $cache_ttl = false; + /** @var int */ + protected $cache_ttl = 0; /** @var array Fetched groups' data */ protected $groups = null; From 34eb913d5a5cbaa865715f2415c4fffc327b17e6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 3 Jan 2023 21:33:47 +0100 Subject: [PATCH 42/42] [ticket/16955] Use runtime_exception instead of \Exception PHPBB3-16955 --- phpBB/phpbb/notification/manager.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index 06a5c6a907..e25c0f2952 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -13,6 +13,7 @@ namespace phpbb\notification; +use phpbb\exception\runtime_exception; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -897,7 +898,7 @@ class manager * @param array $data * * @return type\type_interface - * @throws \Exception When type name is not o notification type + * @throws runtime_exception When type name is not o notification type */ public function get_item_type_class($notification_type_name, $data = array()) { @@ -905,7 +906,7 @@ class manager if (!$item instanceof type\type_interface) { - throw new \Exception('Supplied type name returned invalid service: ' . $notification_type_name); + throw new runtime_exception('Supplied type name returned invalid service: ' . $notification_type_name); } $item->set_initial_data($data); @@ -919,7 +920,7 @@ class manager * @param string $method_name * * @return method\method_interface - * @throws \Exception When object name is not o notification method + * @throws runtime_exception When object name is not o notification method */ public function get_method_class($method_name) { @@ -927,7 +928,7 @@ class manager if (!$object instanceof method\method_interface) { - throw new \Exception('Supplied method name returned invalid service: ' . $method_name); + throw new runtime_exception('Supplied method name returned invalid service: ' . $method_name); } return $object; @@ -940,7 +941,7 @@ class manager * * @return method\method_interface|type\type_interface * @psalm-suppress NullableReturnStatement Invalid service will result in exception - * @throws \Exception When object name is not o notification method or type + * @throws runtime_exception When object name is not o notification method or type */ protected function load_object($object_name) { @@ -953,7 +954,7 @@ class manager if (!$object instanceof method\method_interface && !$object instanceof type\type_interface) { - throw new \Exception('Supplied object name returned invalid service: ' . $object_name); + throw new runtime_exception('Supplied object name returned invalid service: ' . $object_name); } return $object;