From 6057de278f9d3efeb81124cba1eacccde568cb09 Mon Sep 17 00:00:00 2001 From: Thorsten Rinne Date: Wed, 8 Jan 2025 07:15:08 +0100 Subject: [PATCH] chore: upgraded to PHPStan v2 and Rector v2 --- composer.json | 4 +- composer.lock | 117 +++++++++--------- phpmyfaq/index.php | 2 +- .../AuthenticationController.php | 2 +- phpmyfaq/src/phpMyFAQ/User/CurrentUser.php | 2 +- phpmyfaq/src/phpMyFAQ/User/TwoFactor.php | 4 +- phpmyfaq/src/phpMyFAQ/Utils.php | 2 +- tests/phpMyFAQ/User/TwoFactorTest.php | 2 +- 8 files changed, 69 insertions(+), 66 deletions(-) diff --git a/composer.json b/composer.json index e3f504df90..b124c11f24 100644 --- a/composer.json +++ b/composer.json @@ -55,9 +55,9 @@ "mikey179/vfsstream": "^1.6", "phpdocumentor/reflection-docblock": "5.*", "phpmd/phpmd": "@stable", - "phpstan/phpstan": "^1.0.0", + "phpstan/phpstan": "^2", "phpunit/phpunit": "11.*", - "rector/rector": "^1.0.0", + "rector/rector": "^2", "squizlabs/php_codesniffer": "3.*", "symfony/yaml": "7.*", "zircote/swagger-php": "^4.8" diff --git a/composer.lock b/composer.lock index b9471def44..7c5bb8c807 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "830ab849db3a8126e83a44ec06e066df", + "content-hash": "5094e07ff43f1fd832fe07d326c48e57", "packages": [ { "name": "2tvenom/cborencode", @@ -309,16 +309,16 @@ }, { "name": "egulias/email-validator", - "version": "4.0.2", + "version": "4.0.3", "source": { "type": "git", "url": "https://github.com/egulias/EmailValidator.git", - "reference": "ebaaf5be6c0286928352e054f2d5125608e5405e" + "reference": "b115554301161fa21467629f1e1391c1936de517" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/ebaaf5be6c0286928352e054f2d5125608e5405e", - "reference": "ebaaf5be6c0286928352e054f2d5125608e5405e", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/b115554301161fa21467629f1e1391c1936de517", + "reference": "b115554301161fa21467629f1e1391c1936de517", "shasum": "" }, "require": { @@ -364,7 +364,7 @@ ], "support": { "issues": "https://github.com/egulias/EmailValidator/issues", - "source": "https://github.com/egulias/EmailValidator/tree/4.0.2" + "source": "https://github.com/egulias/EmailValidator/tree/4.0.3" }, "funding": [ { @@ -372,7 +372,7 @@ "type": "github" } ], - "time": "2023-10-06T06:47:41+00:00" + "time": "2024-12-27T00:36:43+00:00" }, { "name": "elastic/transport", @@ -4470,8 +4470,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -5214,13 +5214,13 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "3.x-dev" - }, "phpstan": { "includes": [ "extension.neon" ] + }, + "branch-alias": { + "dev-main": "3.x-dev" } }, "autoload": { @@ -5745,16 +5745,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.3.1", + "version": "v5.4.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "8eea230464783aa9671db8eea6f8c6ac5285794b" + "reference": "447a020a1f875a434d62f2a401f53b82a396e494" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/8eea230464783aa9671db8eea6f8c6ac5285794b", - "reference": "8eea230464783aa9671db8eea6f8c6ac5285794b", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/447a020a1f875a434d62f2a401f53b82a396e494", + "reference": "447a020a1f875a434d62f2a401f53b82a396e494", "shasum": "" }, "require": { @@ -5797,22 +5797,22 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.3.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.4.0" }, - "time": "2024-10-08T18:51:32+00:00" + "time": "2024-12-30T11:07:19+00:00" }, { "name": "opis/json-schema", - "version": "2.3.0", + "version": "2.4.1", "source": { "type": "git", "url": "https://github.com/opis/json-schema.git", - "reference": "c48df6d7089a45f01e1c82432348f2d5976f9bfb" + "reference": "712827751c62b465daae6e725bf0cf5ffbf965e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opis/json-schema/zipball/c48df6d7089a45f01e1c82432348f2d5976f9bfb", - "reference": "c48df6d7089a45f01e1c82432348f2d5976f9bfb", + "url": "https://api.github.com/repos/opis/json-schema/zipball/712827751c62b465daae6e725bf0cf5ffbf965e1", + "reference": "712827751c62b465daae6e725bf0cf5ffbf965e1", "shasum": "" }, "require": { @@ -5862,22 +5862,22 @@ ], "support": { "issues": "https://github.com/opis/json-schema/issues", - "source": "https://github.com/opis/json-schema/tree/2.3.0" + "source": "https://github.com/opis/json-schema/tree/2.4.1" }, - "time": "2022-01-08T20:38:03+00:00" + "time": "2024-12-30T20:20:21+00:00" }, { "name": "opis/string", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/opis/string.git", - "reference": "9ebf1a1f873f502f6859d11210b25a4bf5d141e7" + "reference": "ba0b9607b9809462b0e28a11e4881a8d77431feb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opis/string/zipball/9ebf1a1f873f502f6859d11210b25a4bf5d141e7", - "reference": "9ebf1a1f873f502f6859d11210b25a4bf5d141e7", + "url": "https://api.github.com/repos/opis/string/zipball/ba0b9607b9809462b0e28a11e4881a8d77431feb", + "reference": "ba0b9607b9809462b0e28a11e4881a8d77431feb", "shasum": "" }, "require": { @@ -5924,9 +5924,9 @@ ], "support": { "issues": "https://github.com/opis/string/issues", - "source": "https://github.com/opis/string/tree/2.0.1" + "source": "https://github.com/opis/string/tree/2.0.2" }, - "time": "2022-01-14T15:42:23+00:00" + "time": "2024-12-30T21:43:22+00:00" }, { "name": "opis/uri", @@ -6545,20 +6545,20 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.12", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0" + "reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0", - "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7", + "reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -6599,7 +6599,7 @@ "type": "github" } ], - "time": "2024-11-28T22:13:23+00:00" + "time": "2025-01-05T16:43:48+00:00" }, { "name": "phpunit/php-code-coverage", @@ -7027,21 +7027,21 @@ }, { "name": "rector/rector", - "version": "1.2.10", + "version": "2.0.6", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "40f9cf38c05296bd32f444121336a521a293fa61" + "reference": "fa0cb009dc3df084bf549032ae4080a0481a2036" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/40f9cf38c05296bd32f444121336a521a293fa61", - "reference": "40f9cf38c05296bd32f444121336a521a293fa61", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/fa0cb009dc3df084bf549032ae4080a0481a2036", + "reference": "fa0cb009dc3df084bf549032ae4080a0481a2036", "shasum": "" }, "require": { - "php": "^7.2|^8.0", - "phpstan/phpstan": "^1.12.5" + "php": "^7.4|^8.0", + "phpstan/phpstan": "^2.1.1" }, "conflict": { "rector/rector-doctrine": "*", @@ -7074,7 +7074,7 @@ ], "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/1.2.10" + "source": "https://github.com/rectorphp/rector/tree/2.0.6" }, "funding": [ { @@ -7082,7 +7082,7 @@ "type": "github" } ], - "time": "2024-11-08T13:59:10+00:00" + "time": "2025-01-06T10:38:36+00:00" }, { "name": "sebastian/cli-parser", @@ -7256,16 +7256,16 @@ }, { "name": "sebastian/comparator", - "version": "6.2.1", + "version": "6.3.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "43d129d6a0f81c78bee378b46688293eb7ea3739" + "reference": "d4e47a769525c4dd38cea90e5dcd435ddbbc7115" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/43d129d6a0f81c78bee378b46688293eb7ea3739", - "reference": "43d129d6a0f81c78bee378b46688293eb7ea3739", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/d4e47a769525c4dd38cea90e5dcd435ddbbc7115", + "reference": "d4e47a769525c4dd38cea90e5dcd435ddbbc7115", "shasum": "" }, "require": { @@ -7278,6 +7278,9 @@ "require-dev": { "phpunit/phpunit": "^11.4" }, + "suggest": { + "ext-bcmath": "For comparing BcMath\\Number objects" + }, "type": "library", "extra": { "branch-alias": { @@ -7321,7 +7324,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", "security": "https://github.com/sebastianbergmann/comparator/security/policy", - "source": "https://github.com/sebastianbergmann/comparator/tree/6.2.1" + "source": "https://github.com/sebastianbergmann/comparator/tree/6.3.0" }, "funding": [ { @@ -7329,7 +7332,7 @@ "type": "github" } ], - "time": "2024-10-31T05:30:08+00:00" + "time": "2025-01-06T10:28:19+00:00" }, { "name": "sebastian/complexity", @@ -8141,16 +8144,16 @@ }, { "name": "symfony/finder", - "version": "v7.1.6", + "version": "v7.2.2", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "2cb89664897be33f78c65d3d2845954c8d7a43b8" + "reference": "87a71856f2f56e4100373e92529eed3171695cfb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/2cb89664897be33f78c65d3d2845954c8d7a43b8", - "reference": "2cb89664897be33f78c65d3d2845954c8d7a43b8", + "url": "https://api.github.com/repos/symfony/finder/zipball/87a71856f2f56e4100373e92529eed3171695cfb", + "reference": "87a71856f2f56e4100373e92529eed3171695cfb", "shasum": "" }, "require": { @@ -8185,7 +8188,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.1.6" + "source": "https://github.com/symfony/finder/tree/v7.2.2" }, "funding": [ { @@ -8201,7 +8204,7 @@ "type": "tidelift" } ], - "time": "2024-10-01T08:31:23+00:00" + "time": "2024-12-30T19:00:17+00:00" }, { "name": "symfony/yaml", @@ -8484,7 +8487,7 @@ "ext-xmlwriter": "*", "ext-zip": "*" }, - "platform-dev": [], + "platform-dev": {}, "platform-overrides": { "php": "8.2.0" }, diff --git a/phpmyfaq/index.php b/phpmyfaq/index.php index d83561843e..5d3274698f 100755 --- a/phpmyfaq/index.php +++ b/phpmyfaq/index.php @@ -167,7 +167,7 @@ // Validating token from 2FA if given; else: returns error message // if ($token !== '' && !is_null($userId)) { - if (strlen((string)$token) === 6 && is_numeric((string)$token)) { + if (strlen($token) === 6 && is_numeric((string)$token)) { $user = new CurrentUser($faqConfig); $user->getUserById($userId); $tfa = new TwoFactor($faqConfig, $user); diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Administration/AuthenticationController.php b/phpmyfaq/src/phpMyFAQ/Controller/Administration/AuthenticationController.php index 88d1d91a08..be0d66b092 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Administration/AuthenticationController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Administration/AuthenticationController.php @@ -186,7 +186,7 @@ public function check(Request $request): Response return new RedirectResponse('./'); } - $token = Filter::filterVar($request->get('token'), FILTER_VALIDATE_INT); + $token = Filter::filterVar($request->get('token'), FILTER_SANITIZE_SPECIAL_CHARS); $userId = Filter::filterVar($request->get('user-id'), FILTER_VALIDATE_INT); $user = $this->container->get('phpmyfaq.user.current_user'); diff --git a/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php b/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php index d0ba68a737..0fc3ef1b6b 100644 --- a/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php +++ b/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php @@ -486,7 +486,7 @@ public static function getCurrentUserGroupId(?CurrentUser $user = null): array $currentGroups = [-1]; } - if (0 === (is_countable($currentGroups) ? count($currentGroups) : 0)) { + if (count($currentGroups)) { $currentGroups = [-1]; } } else { diff --git a/phpmyfaq/src/phpMyFAQ/User/TwoFactor.php b/phpmyfaq/src/phpMyFAQ/User/TwoFactor.php index dbc9b67a51..f322c8626c 100644 --- a/phpmyfaq/src/phpMyFAQ/User/TwoFactor.php +++ b/phpmyfaq/src/phpMyFAQ/User/TwoFactor.php @@ -85,9 +85,9 @@ public function getSecret(CurrentUser $currentUser): string|null /** * Validates a given token. Returns true if the token is correct. */ - public function validateToken(int $token, int $userId): bool + public function validateToken(string $token, int $userId): bool { - if (strlen((string)$token) !== 6) { + if (strlen($token) !== 6) { return false; } diff --git a/phpmyfaq/src/phpMyFAQ/Utils.php b/phpmyfaq/src/phpMyFAQ/Utils.php index 5afb8a1d4c..02b59050a7 100644 --- a/phpmyfaq/src/phpMyFAQ/Utils.php +++ b/phpmyfaq/src/phpMyFAQ/Utils.php @@ -250,7 +250,7 @@ public static function getHostFromUrl(string $url): ?string /** * Moves given key of an array to the top * - * @param array $array + * @param array> $array */ public static function moveToTop(array &$array, string $key): void { diff --git a/tests/phpMyFAQ/User/TwoFactorTest.php b/tests/phpMyFAQ/User/TwoFactorTest.php index ed231538fa..8e25a91799 100644 --- a/tests/phpMyFAQ/User/TwoFactorTest.php +++ b/tests/phpMyFAQ/User/TwoFactorTest.php @@ -88,7 +88,7 @@ public function testValidateToken(): void $property->setAccessible(true); $property->setValue($this->twoFactor, $twoFactorAuth); - $result = $this->twoFactor->validateToken(123456, 1); + $result = $this->twoFactor->validateToken('123456', 1); $this->assertTrue($result); }