From 2911a4807ed2a22178ea7c0149c3bfdd62558cb5 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Mon, 4 Nov 2024 21:17:08 +0100 Subject: [PATCH] Bump phpstan Fixes a number of phpstan issues. --- Makefile | 2 +- composer.lock | 107 +++++++++--------- phpstan.neon | 6 - src/DocBlock/StandardTagFactory.php | 5 - src/DocBlock/Tags/Example.php | 4 +- .../Tags/Factory/AbstractPHPStanFactory.php | 4 +- src/DocBlock/Tags/Factory/TemplateFactory.php | 4 - src/DocBlock/Tags/MethodParameter.php | 3 - 8 files changed, 61 insertions(+), 74 deletions(-) diff --git a/Makefile b/Makefile index 4d798eb3..5420da71 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ fix-code-style: .PHONY: static-code-analysis static-code-analysis: vendor ## Runs a static code analysis with phpstan/phpstan and vimeo/psalm - docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.4 vendor/bin/phpstan --configuration=phpstan.neon + docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.4 vendor/bin/phpstan --configuration=phpstan.neon --memory-limit=1024M docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.4 vendor/bin/psalm.phar .PHONY: test diff --git a/composer.lock b/composer.lock index a4cdb64b..9433fbe7 100644 --- a/composer.lock +++ b/composer.lock @@ -166,22 +166,24 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.13.0", + "version": "1.33.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "33aefcdab42900e36366d0feab6206e2dd68f947" + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/33aefcdab42900e36366d0feab6206e2dd68f947", - "reference": "33aefcdab42900e36366d0feab6206e2dd68f947", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", "shasum": "" }, "require": { "php": "^7.2 || ^8.0" }, "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^1.5", @@ -205,9 +207,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.13.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" }, - "time": "2022-10-21T09:57:39+00:00" + "time": "2024-10-13T11:25:22+00:00" }, { "name": "webmozart/assert", @@ -701,28 +703,27 @@ }, { "name": "phpstan/extension-installer", - "version": "1.1.0", + "version": "1.4.3", "source": { "type": "git", "url": "https://github.com/phpstan/extension-installer.git", - "reference": "66c7adc9dfa38b6b5838a9fb728b68a7d8348051" + "reference": "85e90b3942d06b2326fba0403ec24fe912372936" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/66c7adc9dfa38b6b5838a9fb728b68a7d8348051", - "reference": "66c7adc9dfa38b6b5838a9fb728b68a7d8348051", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936", "shasum": "" }, "require": { - "composer-plugin-api": "^1.1 || ^2.0", - "php": "^7.1 || ^8.0", - "phpstan/phpstan": ">=0.11.6" + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0 || ^2.0" }, "require-dev": { - "composer/composer": "^1.8", - "phing/phing": "^2.16.3", + "composer/composer": "^2.0", "php-parallel-lint/php-parallel-lint": "^1.2.0", - "phpstan/phpstan-strict-rules": "^0.11 || ^0.12" + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" }, "type": "composer-plugin", "extra": { @@ -738,24 +739,28 @@ "MIT" ], "description": "Composer plugin for automatic installation of PHPStan extensions", + "keywords": [ + "dev", + "static analysis" + ], "support": { "issues": "https://github.com/phpstan/extension-installer/issues", - "source": "https://github.com/phpstan/extension-installer/tree/1.1.0" + "source": "https://github.com/phpstan/extension-installer/tree/1.4.3" }, - "time": "2020-12-13T13:06:13+00:00" + "time": "2024-09-04T20:21:43+00:00" }, { "name": "phpstan/phpstan", - "version": "1.8.2", + "version": "1.12.7", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "c53312ecc575caf07b0e90dee43883fdf90ca67c" + "reference": "dc2b9976bd8b0f84ec9b0e50cc35378551de7af0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/c53312ecc575caf07b0e90dee43883fdf90ca67c", - "reference": "c53312ecc575caf07b0e90dee43883fdf90ca67c", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dc2b9976bd8b0f84ec9b0e50cc35378551de7af0", + "reference": "dc2b9976bd8b0f84ec9b0e50cc35378551de7af0", "shasum": "" }, "require": { @@ -779,9 +784,16 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.8.2" + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" }, "funding": [ { @@ -791,42 +803,34 @@ { "url": "https://github.com/phpstan", "type": "github" - }, - { - "url": "https://www.patreon.com/phpstan", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", - "type": "tidelift" } ], - "time": "2022-07-20T09:57:31+00:00" + "time": "2024-10-18T11:12:07+00:00" }, { "name": "phpstan/phpstan-mockery", - "version": "1.1.0", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-mockery.git", - "reference": "245b17ccd00f04be3c6b9fc6645f63793b37b2ea" + "reference": "98cac6e256b4ee60fdeb26a7dd81bb271b454e80" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-mockery/zipball/245b17ccd00f04be3c6b9fc6645f63793b37b2ea", - "reference": "245b17ccd00f04be3c6b9fc6645f63793b37b2ea", + "url": "https://api.github.com/repos/phpstan/phpstan-mockery/zipball/98cac6e256b4ee60fdeb26a7dd81bb271b454e80", + "reference": "98cac6e256b4ee60fdeb26a7dd81bb271b454e80", "shasum": "" }, "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.5.0" + "phpstan/phpstan": "^1.12" }, "require-dev": { - "mockery/mockery": "^1.2.4", + "mockery/mockery": "^1.6.11", "nikic/php-parser": "^4.13.0", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.0", - "phpstan/phpstan-strict-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.4", + "phpstan/phpstan-strict-rules": "^1.6", "phpunit/phpunit": "^9.5" }, "type": "phpstan-extension", @@ -849,33 +853,34 @@ "description": "PHPStan Mockery extension", "support": { "issues": "https://github.com/phpstan/phpstan-mockery/issues", - "source": "https://github.com/phpstan/phpstan-mockery/tree/1.1.0" + "source": "https://github.com/phpstan/phpstan-mockery/tree/1.1.3" }, - "time": "2022-05-09T13:12:35+00:00" + "time": "2024-09-11T15:47:29+00:00" }, { "name": "phpstan/phpstan-webmozart-assert", - "version": "1.2.0", + "version": "1.2.11", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-webmozart-assert.git", - "reference": "a7f12958f0c5e1f948df99a84aa03fa8df544992" + "reference": "960dd44e8466191590dd0d7940d3e9496eebebbd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-webmozart-assert/zipball/a7f12958f0c5e1f948df99a84aa03fa8df544992", - "reference": "a7f12958f0c5e1f948df99a84aa03fa8df544992", + "url": "https://api.github.com/repos/phpstan/phpstan-webmozart-assert/zipball/960dd44e8466191590dd0d7940d3e9496eebebbd", + "reference": "960dd44e8466191590dd0d7940d3e9496eebebbd", "shasum": "" }, "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.6.4" + "phpstan/phpstan": "^1.12" }, "require-dev": { "nikic/php-parser": "^4.13.0", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.0", - "phpstan/phpstan-strict-rules": "^1.0", + "phpstan/phpstan-deprecation-rules": "^1.2", + "phpstan/phpstan-phpunit": "^1.4", + "phpstan/phpstan-strict-rules": "^1.6", "phpunit/phpunit": "^9.5", "webmozart/assert": "^1.11.0" }, @@ -899,9 +904,9 @@ "description": "PHPStan webmozart/assert extension", "support": { "issues": "https://github.com/phpstan/phpstan-webmozart-assert/issues", - "source": "https://github.com/phpstan/phpstan-webmozart-assert/tree/1.2.0" + "source": "https://github.com/phpstan/phpstan-webmozart-assert/tree/1.2.11" }, - "time": "2022-06-06T08:42:28+00:00" + "time": "2024-09-11T15:48:08+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/phpstan.neon b/phpstan.neon index 06b8fded..a43a75f3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,11 +2,5 @@ parameters: level: max ignoreErrors: - '#Method phpDocumentor\\Reflection\\DocBlock\\StandardTagFactory::createTag\(\) should return phpDocumentor\\Reflection\\DocBlock\\Tag but returns mixed#' - - "#Strict comparison using !== between array{'name', 'type'} and array{'name', 'type'} will always evaluate to false#" - - '#Call to static method Webmozart\\Assert\\Assert::implementsInterface\(\) with class-string#' - - '#Class PHPStan\\PhpDocParser\\Lexer\\Lexer does not have a constructor and must be instantiated without any parameters\.#' - - '#Class PHPStan\\PhpDocParser\\Parser\\ConstExprParser constructor invoked with 3 parameters, 0\-1 required\.#' - - '#Class PHPStan\\PhpDocParser\\Parser\\PhpDocParser constructor invoked with 6 parameters, 2\-3 required\.#' - - '#Class PHPStan\\PhpDocParser\\Parser\\TypeParser constructor invoked with 3 parameters\, 0\-1 required\.#' paths: - src diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index e08db7b0..d029cd1b 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -47,7 +47,6 @@ use function array_merge; use function array_slice; use function call_user_func_array; -use function count; use function get_class; use function is_object; use function preg_match; @@ -205,10 +204,6 @@ private function extractTagParts(string $tagLine): array ); } - if (count($matches) < 3) { - $matches[] = ''; - } - return array_slice($matches, 1); } diff --git a/src/DocBlock/Tags/Example.php b/src/DocBlock/Tags/Example.php index fd9ef6eb..3ddbb686 100644 --- a/src/DocBlock/Tags/Example.php +++ b/src/DocBlock/Tags/Example.php @@ -94,10 +94,10 @@ public static function create(string $body): ?Tag $filePath = null; $fileUri = null; - if ($matches[1] !== '') { + if (array_key_exists(1, $matches) && $matches[1] !== '') { $filePath = $matches[1]; } else { - $fileUri = $matches[2]; + $fileUri = array_key_exists(2, $matches) ? $matches[2] : ''; } $startingLine = 1; diff --git a/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php b/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php index b1618bfa..876d15f1 100644 --- a/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php +++ b/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php @@ -104,12 +104,12 @@ private function tokenizeLine(string $tagLine): TokenIterator $fixed[] = [ rtrim($token[Lexer::VALUE_OFFSET], " \t"), Lexer::TOKEN_PHPDOC_EOL, - $token[2] ?? null, + $token[2], ]; $fixed[] = [ ltrim($token[Lexer::VALUE_OFFSET], "\n\r"), Lexer::TOKEN_HORIZONTAL_WS, - ($token[2] ?? null) + 1, + $token[2] + 1, ]; continue; } diff --git a/src/DocBlock/Tags/Factory/TemplateFactory.php b/src/DocBlock/Tags/Factory/TemplateFactory.php index 0ebf26b5..9e4b3c89 100644 --- a/src/DocBlock/Tags/Factory/TemplateFactory.php +++ b/src/DocBlock/Tags/Factory/TemplateFactory.php @@ -4,7 +4,6 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; -use InvalidArgumentException; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\Tags\Template; @@ -36,9 +35,6 @@ public function create(PhpDocTagNode $node, Context $context): Tag Assert::isInstanceOf($tagValue, TemplateTagValueNode::class); $name = $tagValue->name; - if ($name === '') { - throw new InvalidArgumentException('Template name cannot be empty'); - } $description = $tagValue->getAttribute('description'); if (is_string($description) === false) { diff --git a/src/DocBlock/Tags/MethodParameter.php b/src/DocBlock/Tags/MethodParameter.php index b448a4f8..ceb87024 100644 --- a/src/DocBlock/Tags/MethodParameter.php +++ b/src/DocBlock/Tags/MethodParameter.php @@ -15,9 +15,6 @@ use phpDocumentor\Reflection\DocBlock\Tags\Factory\MethodParameterFactory; use phpDocumentor\Reflection\Type; -use function implode; -use function is_array; - final class MethodParameter { private Type $type;