From 15dc3e0d81b711c38d02fb33fe4482dfa570951c Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 1 Feb 2022 22:15:54 +0000 Subject: [PATCH] Update dependency slevomat/coding-standard to v7 --- .gitignore | 2 +- build-cs/.gitignore | 1 - build-cs/composer.json | 2 +- build-cs/composer.lock | 327 ++++++++++++++++++ phpcs.xml | 98 ++++-- .../MockObjectTypeNodeResolverExtension.php | 7 +- src/Rules/PHPUnit/AssertRuleHelper.php | 2 + .../PHPUnit/AssertSameBooleanExpectedRule.php | 14 +- .../PHPUnit/AssertSameNullExpectedRule.php | 14 +- src/Rules/PHPUnit/AssertSameWithCountRule.php | 17 +- src/Rules/PHPUnit/MockMethodCallRule.php | 15 +- .../PHPUnit/ShouldCallParentMethodsRule.php | 10 +- .../AssertFunctionTypeSpecifyingExtension.php | 3 + .../AssertTypeSpecifyingExtensionHelper.php | 121 +++---- ...cationMockerDynamicReturnTypeExtension.php | 3 +- .../MockBuilderDynamicReturnTypeExtension.php | 4 +- .../MockObjectDynamicReturnTypeExtension.php | 8 +- .../AssertSameBooleanExpectedRuleTest.php | 5 +- ...AssertSameMethodDifferentTypesRuleTest.php | 5 +- .../AssertSameNullExpectedRuleTest.php | 5 +- ...SameStaticMethodDifferentTypesRuleTest.php | 5 +- .../PHPUnit/AssertSameWithCountRuleTest.php | 5 +- .../Rules/PHPUnit/MockMethodCallRuleTest.php | 5 +- .../ShouldCallParentMethodsRuleTest.php | 5 +- ...ertFunctionTypeSpecifyingExtensionTest.php | 3 +- ...ssertMethodTypeSpecifyingExtensionTest.php | 2 - 26 files changed, 554 insertions(+), 134 deletions(-) create mode 100644 build-cs/composer.lock diff --git a/.gitignore b/.gitignore index d6a83e5..2db2131 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /tests/tmp /vendor -composer.lock +/composer.lock .phpunit.result.cache diff --git a/build-cs/.gitignore b/build-cs/.gitignore index ff72e2d..61ead86 100644 --- a/build-cs/.gitignore +++ b/build-cs/.gitignore @@ -1,2 +1 @@ -/composer.lock /vendor diff --git a/build-cs/composer.json b/build-cs/composer.json index cc6a498..e307971 100644 --- a/build-cs/composer.json +++ b/build-cs/composer.json @@ -2,7 +2,7 @@ "require-dev": { "consistence-community/coding-standard": "^3.10", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", - "slevomat/coding-standard": "^6.4" + "slevomat/coding-standard": "^7.0" }, "config": { "allow-plugins": { diff --git a/build-cs/composer.lock b/build-cs/composer.lock new file mode 100644 index 0000000..70af78f --- /dev/null +++ b/build-cs/composer.lock @@ -0,0 +1,327 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "4485bbedba7bcc71ace5f69dbb9b6c47", + "packages": [], + "packages-dev": [ + { + "name": "consistence-community/coding-standard", + "version": "3.11.1", + "source": { + "type": "git", + "url": "https://github.com/consistence-community/coding-standard.git", + "reference": "4632fead8c9ee8f50044fcbce9f66c797b34c0df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/consistence-community/coding-standard/zipball/4632fead8c9ee8f50044fcbce9f66c797b34c0df", + "reference": "4632fead8c9ee8f50044fcbce9f66c797b34c0df", + "shasum": "" + }, + "require": { + "php": ">=7.4", + "slevomat/coding-standard": "~7.0", + "squizlabs/php_codesniffer": "~3.6.0" + }, + "replace": { + "consistence/coding-standard": "3.10.*" + }, + "require-dev": { + "phing/phing": "2.16.4", + "php-parallel-lint/php-parallel-lint": "1.3.0", + "phpunit/phpunit": "9.5.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Consistence\\": [ + "Consistence" + ] + }, + "classmap": [ + "Consistence" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "VaĊĦek Purchart", + "email": "me@vasekpurchart.cz", + "homepage": "http://vasekpurchart.cz" + } + ], + "description": "Consistence - Coding Standard - PHP Code Sniffer rules", + "keywords": [ + "Coding Standard", + "PHPCodeSniffer", + "codesniffer", + "coding", + "cs", + "phpcs", + "ruleset", + "sniffer", + "standard" + ], + "support": { + "issues": "https://github.com/consistence-community/coding-standard/issues", + "source": "https://github.com/consistence-community/coding-standard/tree/3.11.1" + }, + "time": "2021-05-03T18:13:22+00:00" + }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.2", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2022-02-04T12:51:07+00:00" + }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "dbc093d7af60eff5cd575d2ed761b15ed40bd08e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/dbc093d7af60eff5cd575d2ed761b15ed40bd08e", + "reference": "dbc093d7af60eff5cd575d2ed761b15ed40bd08e", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "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.2.0" + }, + "time": "2021-09-16T20:46:02+00:00" + }, + { + "name": "slevomat/coding-standard", + "version": "7.0.18", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "b81ac84f41a4797dc25c8ede1b0718e2a74be0fc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/b81ac84f41a4797dc25c8ede1b0718e2a74be0fc", + "reference": "b81ac84f41a4797dc25c8ede1b0718e2a74be0fc", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", + "php": "^7.1 || ^8.0", + "phpstan/phpdoc-parser": "^1.0.0", + "squizlabs/php_codesniffer": "^3.6.1" + }, + "require-dev": { + "phing/phing": "2.17.0", + "php-parallel-lint/php-parallel-lint": "1.3.1", + "phpstan/phpstan": "1.2.0", + "phpstan/phpstan-deprecation-rules": "1.0.0", + "phpstan/phpstan-phpunit": "1.0.0", + "phpstan/phpstan-strict-rules": "1.1.0", + "phpunit/phpunit": "7.5.20|8.5.21|9.5.10" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/7.0.18" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2021-12-07T17:19:06+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.6.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a", + "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2021-12-12T21:44:58+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.2.0" +} diff --git a/phpcs.xml b/phpcs.xml index ce6e811..95032a6 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,5 +1,6 @@ - + + @@ -8,58 +9,103 @@ src tests + - - + + - + + + + + - + - - - - - + + + + + 10 - - - + + 10 + - - - + + + + + 10 + + + - - + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - tests/tmp + + tests/*/data diff --git a/src/PhpDoc/PHPUnit/MockObjectTypeNodeResolverExtension.php b/src/PhpDoc/PHPUnit/MockObjectTypeNodeResolverExtension.php index 955b818..7225d6d 100644 --- a/src/PhpDoc/PHPUnit/MockObjectTypeNodeResolverExtension.php +++ b/src/PhpDoc/PHPUnit/MockObjectTypeNodeResolverExtension.php @@ -2,6 +2,7 @@ namespace PHPStan\PhpDoc\PHPUnit; +use PHPStan\Analyser\NameScope; use PHPStan\PhpDoc\TypeNodeResolver; use PHPStan\PhpDoc\TypeNodeResolverAwareExtension; use PHPStan\PhpDoc\TypeNodeResolverExtension; @@ -9,7 +10,9 @@ use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode; use PHPStan\Type\NeverType; use PHPStan\Type\Type; +use PHPStan\Type\TypeCombinator; use PHPStan\Type\TypeWithClassName; +use function array_key_exists; class MockObjectTypeNodeResolverExtension implements TypeNodeResolverExtension, TypeNodeResolverAwareExtension { @@ -27,7 +30,7 @@ public function getCacheKey(): string return 'phpunit-v1'; } - public function resolve(TypeNode $typeNode, \PHPStan\Analyser\NameScope $nameScope): ?Type + public function resolve(TypeNode $typeNode, NameScope $nameScope): ?Type { if (!$typeNode instanceof UnionTypeNode) { return null; @@ -45,7 +48,7 @@ public function resolve(TypeNode $typeNode, \PHPStan\Analyser\NameScope $nameSco } if (array_key_exists($type->getClassName(), $mockClassNames)) { - $resultType = \PHPStan\Type\TypeCombinator::intersect(...$types); + $resultType = TypeCombinator::intersect(...$types); if ($resultType instanceof NeverType) { continue; } diff --git a/src/Rules/PHPUnit/AssertRuleHelper.php b/src/Rules/PHPUnit/AssertRuleHelper.php index e8edc50..9673537 100644 --- a/src/Rules/PHPUnit/AssertRuleHelper.php +++ b/src/Rules/PHPUnit/AssertRuleHelper.php @@ -5,6 +5,8 @@ use PhpParser\Node; use PHPStan\Analyser\Scope; use PHPStan\Type\ObjectType; +use function in_array; +use function strtolower; class AssertRuleHelper { diff --git a/src/Rules/PHPUnit/AssertSameBooleanExpectedRule.php b/src/Rules/PHPUnit/AssertSameBooleanExpectedRule.php index 9712185..6be390a 100644 --- a/src/Rules/PHPUnit/AssertSameBooleanExpectedRule.php +++ b/src/Rules/PHPUnit/AssertSameBooleanExpectedRule.php @@ -3,18 +3,24 @@ namespace PHPStan\Rules\PHPUnit; use PhpParser\Node; +use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Expr\StaticCall; +use PhpParser\NodeAbstract; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\Constant\ConstantBooleanType; +use function count; +use function strtolower; /** - * @implements \PHPStan\Rules\Rule<\PhpParser\NodeAbstract> + * @implements Rule */ -class AssertSameBooleanExpectedRule implements \PHPStan\Rules\Rule +class AssertSameBooleanExpectedRule implements Rule { public function getNodeType(): string { - return \PhpParser\NodeAbstract::class; + return NodeAbstract::class; } public function processNode(Node $node, Scope $scope): array @@ -23,7 +29,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - /** @var \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node */ + /** @var MethodCall|StaticCall $node */ $node = $node; if (count($node->getArgs()) < 2) { diff --git a/src/Rules/PHPUnit/AssertSameNullExpectedRule.php b/src/Rules/PHPUnit/AssertSameNullExpectedRule.php index 9337cc8..8d2b2aa 100644 --- a/src/Rules/PHPUnit/AssertSameNullExpectedRule.php +++ b/src/Rules/PHPUnit/AssertSameNullExpectedRule.php @@ -3,18 +3,24 @@ namespace PHPStan\Rules\PHPUnit; use PhpParser\Node; +use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Expr\StaticCall; +use PhpParser\NodeAbstract; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\NullType; +use function count; +use function strtolower; /** - * @implements \PHPStan\Rules\Rule<\PhpParser\NodeAbstract> + * @implements Rule */ -class AssertSameNullExpectedRule implements \PHPStan\Rules\Rule +class AssertSameNullExpectedRule implements Rule { public function getNodeType(): string { - return \PhpParser\NodeAbstract::class; + return NodeAbstract::class; } public function processNode(Node $node, Scope $scope): array @@ -23,7 +29,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - /** @var \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node */ + /** @var MethodCall|StaticCall $node */ $node = $node; if (count($node->getArgs()) < 2) { diff --git a/src/Rules/PHPUnit/AssertSameWithCountRule.php b/src/Rules/PHPUnit/AssertSameWithCountRule.php index 3777b3f..1f1a3ab 100644 --- a/src/Rules/PHPUnit/AssertSameWithCountRule.php +++ b/src/Rules/PHPUnit/AssertSameWithCountRule.php @@ -2,19 +2,26 @@ namespace PHPStan\Rules\PHPUnit; +use Countable; use PhpParser\Node; +use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Expr\StaticCall; +use PhpParser\NodeAbstract; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\ObjectType; +use function count; +use function strtolower; /** - * @implements \PHPStan\Rules\Rule<\PhpParser\NodeAbstract> + * @implements Rule */ -class AssertSameWithCountRule implements \PHPStan\Rules\Rule +class AssertSameWithCountRule implements Rule { public function getNodeType(): string { - return \PhpParser\NodeAbstract::class; + return NodeAbstract::class; } public function processNode(Node $node, Scope $scope): array @@ -23,7 +30,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - /** @var \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node */ + /** @var MethodCall|StaticCall $node */ $node = $node; if (count($node->getArgs()) < 2) { @@ -53,7 +60,7 @@ public function processNode(Node $node, Scope $scope): array ) { $type = $scope->getType($right->var); - if ((new ObjectType(\Countable::class))->isSuperTypeOf($type)->yes()) { + if ((new ObjectType(Countable::class))->isSuperTypeOf($type)->yes()) { return [ 'You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()).', ]; diff --git a/src/Rules/PHPUnit/MockMethodCallRule.php b/src/Rules/PHPUnit/MockMethodCallRule.php index d7551dc..0007aa9 100644 --- a/src/Rules/PHPUnit/MockMethodCallRule.php +++ b/src/Rules/PHPUnit/MockMethodCallRule.php @@ -3,18 +3,25 @@ namespace PHPStan\Rules\PHPUnit; use PhpParser\Node; +use PhpParser\Node\Expr\MethodCall; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\IntersectionType; use PHPStan\Type\ObjectType; use PHPUnit\Framework\MockObject\Builder\InvocationMocker; use PHPUnit\Framework\MockObject\MockObject; +use function array_filter; +use function count; +use function implode; +use function in_array; +use function sprintf; /** - * @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\MethodCall> + * @implements Rule */ -class MockMethodCallRule implements \PHPStan\Rules\Rule +class MockMethodCallRule implements Rule { public function getNodeType(): string @@ -48,7 +55,7 @@ public function processNode(Node $node, Scope $scope): array && in_array(MockObject::class, $type->getReferencedClasses(), true) && !$type->hasMethod($method)->yes() ) { - $mockClass = array_filter($type->getReferencedClasses(), function (string $class): bool { + $mockClass = array_filter($type->getReferencedClasses(), static function (string $class): bool { return $class !== MockObject::class; }); @@ -56,7 +63,7 @@ public function processNode(Node $node, Scope $scope): array sprintf( 'Trying to mock an undefined method %s() on class %s.', $method, - \implode('&', $mockClass) + implode('&', $mockClass) ), ]; } diff --git a/src/Rules/PHPUnit/ShouldCallParentMethodsRule.php b/src/Rules/PHPUnit/ShouldCallParentMethodsRule.php index de8a778..0141406 100644 --- a/src/Rules/PHPUnit/ShouldCallParentMethodsRule.php +++ b/src/Rules/PHPUnit/ShouldCallParentMethodsRule.php @@ -5,13 +5,17 @@ use PhpParser\Node; use PHPStan\Analyser\Scope; use PHPStan\Node\InClassMethodNode; +use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPUnit\Framework\TestCase; +use function in_array; +use function sprintf; +use function strtolower; /** - * @implements \PHPStan\Rules\Rule + * @implements Rule */ -class ShouldCallParentMethodsRule implements \PHPStan\Rules\Rule +class ShouldCallParentMethodsRule implements Rule { public function getNodeType(): string @@ -62,9 +66,7 @@ public function processNode(Node $node, Scope $scope): array /** * @param Node\Stmt[]|null $stmts - * @param string $methodName * - * @return bool */ private function hasParentClassCall(?array $stmts, string $methodName): bool { diff --git a/src/Type/PHPUnit/Assert/AssertFunctionTypeSpecifyingExtension.php b/src/Type/PHPUnit/Assert/AssertFunctionTypeSpecifyingExtension.php index e20e13d..31805a3 100644 --- a/src/Type/PHPUnit/Assert/AssertFunctionTypeSpecifyingExtension.php +++ b/src/Type/PHPUnit/Assert/AssertFunctionTypeSpecifyingExtension.php @@ -10,6 +10,9 @@ use PHPStan\Analyser\TypeSpecifierContext; use PHPStan\Reflection\FunctionReflection; use PHPStan\Type\FunctionTypeSpecifyingExtension; +use function strlen; +use function strpos; +use function substr; class AssertFunctionTypeSpecifyingExtension implements FunctionTypeSpecifyingExtension, TypeSpecifierAwareExtension { diff --git a/src/Type/PHPUnit/Assert/AssertTypeSpecifyingExtensionHelper.php b/src/Type/PHPUnit/Assert/AssertTypeSpecifyingExtensionHelper.php index 2cd354c..36203e6 100644 --- a/src/Type/PHPUnit/Assert/AssertTypeSpecifyingExtensionHelper.php +++ b/src/Type/PHPUnit/Assert/AssertTypeSpecifyingExtensionHelper.php @@ -2,8 +2,12 @@ namespace PHPStan\Type\PHPUnit\Assert; +use Closure; use PhpParser\Node\Arg; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\Identical; +use PhpParser\Node\Expr\BooleanNot; +use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Instanceof_; use PhpParser\Node\Name; @@ -12,17 +16,21 @@ use PHPStan\Analyser\TypeSpecifier; use PHPStan\Analyser\TypeSpecifierContext; use PHPStan\Type\Constant\ConstantStringType; +use ReflectionObject; +use function array_key_exists; +use function count; +use function strlen; +use function strpos; +use function substr; class AssertTypeSpecifyingExtensionHelper { - /** @var \Closure[] */ + /** @var Closure[] */ private static $resolvers; /** - * @param string $name - * @param \PhpParser\Node\Arg[] $args - * @return bool + * @param Arg[] $args */ public static function isSupported( string $name, @@ -37,9 +45,9 @@ public static function isSupported( } $resolver = $resolvers[$trimmedName]; - $resolverReflection = new \ReflectionObject($resolver); + $resolverReflection = new ReflectionObject($resolver); - return count($args) >= (count($resolverReflection->getMethod('__invoke')->getParameters()) - 1); + return count($args) >= count($resolverReflection->getMethod('__invoke')->getParameters()) - 1; } private static function trimName(string $name): string @@ -62,11 +70,7 @@ private static function trimName(string $name): string } /** - * @param TypeSpecifier $typeSpecifier - * @param Scope $scope - * @param string $name - * @param \PhpParser\Node\Arg[] $args $args - * @return SpecifiedTypes + * @param Arg[] $args $args */ public static function specifyTypes( TypeSpecifier $typeSpecifier, @@ -87,16 +91,13 @@ public static function specifyTypes( } /** - * @param Scope $scope - * @param string $name - * @param \PhpParser\Node\Arg[] $args - * @return \PhpParser\Node\Expr|null + * @param Arg[] $args */ private static function createExpression( Scope $scope, string $name, array $args - ): ?\PhpParser\Node\Expr + ): ?Expr { $trimmedName = self::trimName($name); $resolvers = self::getExpressionResolvers(); @@ -107,88 +108,88 @@ private static function createExpression( } if (strpos($name, 'Not') !== false) { - $expression = new \PhpParser\Node\Expr\BooleanNot($expression); + $expression = new BooleanNot($expression); } return $expression; } /** - * @return \Closure[] + * @return Closure[] */ private static function getExpressionResolvers(): array { if (self::$resolvers === null) { self::$resolvers = [ - 'InstanceOf' => function (Scope $scope, Arg $class, Arg $object): ?Instanceof_ { + 'InstanceOf' => static function (Scope $scope, Arg $class, Arg $object): ?Instanceof_ { $classType = $scope->getType($class->value); if (!$classType instanceof ConstantStringType) { return null; } - return new \PhpParser\Node\Expr\Instanceof_( + return new Instanceof_( $object->value, - new \PhpParser\Node\Name($classType->getValue()) + new Name($classType->getValue()) ); }, - 'Same' => function (Scope $scope, Arg $expected, Arg $actual): Identical { - return new \PhpParser\Node\Expr\BinaryOp\Identical( + 'Same' => static function (Scope $scope, Arg $expected, Arg $actual): Identical { + return new Identical( $expected->value, $actual->value ); }, - 'True' => function (Scope $scope, Arg $actual): Identical { - return new \PhpParser\Node\Expr\BinaryOp\Identical( + 'True' => static function (Scope $scope, Arg $actual): Identical { + return new Identical( $actual->value, - new \PhpParser\Node\Expr\ConstFetch(new Name('true')) + new ConstFetch(new Name('true')) ); }, - 'False' => function (Scope $scope, Arg $actual): Identical { - return new \PhpParser\Node\Expr\BinaryOp\Identical( + 'False' => static function (Scope $scope, Arg $actual): Identical { + return new Identical( $actual->value, - new \PhpParser\Node\Expr\ConstFetch(new Name('false')) + new ConstFetch(new Name('false')) ); }, - 'Null' => function (Scope $scope, Arg $actual): Identical { - return new \PhpParser\Node\Expr\BinaryOp\Identical( + 'Null' => static function (Scope $scope, Arg $actual): Identical { + return new Identical( $actual->value, - new \PhpParser\Node\Expr\ConstFetch(new Name('null')) + new ConstFetch(new Name('null')) ); }, - 'IsArray' => function (Scope $scope, Arg $actual): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('is_array'), [$actual]); + 'IsArray' => static function (Scope $scope, Arg $actual): FuncCall { + return new FuncCall(new Name('is_array'), [$actual]); }, - 'IsBool' => function (Scope $scope, Arg $actual): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('is_bool'), [$actual]); + 'IsBool' => static function (Scope $scope, Arg $actual): FuncCall { + return new FuncCall(new Name('is_bool'), [$actual]); }, - 'IsCallable' => function (Scope $scope, Arg $actual): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('is_callable'), [$actual]); + 'IsCallable' => static function (Scope $scope, Arg $actual): FuncCall { + return new FuncCall(new Name('is_callable'), [$actual]); }, - 'IsFloat' => function (Scope $scope, Arg $actual): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('is_float'), [$actual]); + 'IsFloat' => static function (Scope $scope, Arg $actual): FuncCall { + return new FuncCall(new Name('is_float'), [$actual]); }, - 'IsInt' => function (Scope $scope, Arg $actual): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('is_int'), [$actual]); + 'IsInt' => static function (Scope $scope, Arg $actual): FuncCall { + return new FuncCall(new Name('is_int'), [$actual]); }, - 'IsIterable' => function (Scope $scope, Arg $actual): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('is_iterable'), [$actual]); + 'IsIterable' => static function (Scope $scope, Arg $actual): FuncCall { + return new FuncCall(new Name('is_iterable'), [$actual]); }, - 'IsNumeric' => function (Scope $scope, Arg $actual): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('is_numeric'), [$actual]); + 'IsNumeric' => static function (Scope $scope, Arg $actual): FuncCall { + return new FuncCall(new Name('is_numeric'), [$actual]); }, - 'IsObject' => function (Scope $scope, Arg $actual): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('is_object'), [$actual]); + 'IsObject' => static function (Scope $scope, Arg $actual): FuncCall { + return new FuncCall(new Name('is_object'), [$actual]); }, - 'IsResource' => function (Scope $scope, Arg $actual): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('is_resource'), [$actual]); + 'IsResource' => static function (Scope $scope, Arg $actual): FuncCall { + return new FuncCall(new Name('is_resource'), [$actual]); }, - 'IsString' => function (Scope $scope, Arg $actual): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('is_string'), [$actual]); + 'IsString' => static function (Scope $scope, Arg $actual): FuncCall { + return new FuncCall(new Name('is_string'), [$actual]); }, - 'IsScalar' => function (Scope $scope, Arg $actual): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('is_scalar'), [$actual]); + 'IsScalar' => static function (Scope $scope, Arg $actual): FuncCall { + return new FuncCall(new Name('is_scalar'), [$actual]); }, - 'InternalType' => function (Scope $scope, Arg $type, Arg $value): ?FuncCall { + 'InternalType' => static function (Scope $scope, Arg $type, Arg $value): ?FuncCall { $typeType = $scope->getType($type->value); if (!$typeType instanceof ConstantStringType) { return null; @@ -245,18 +246,18 @@ private static function getExpressionResolvers(): array return null; } - return new \PhpParser\Node\Expr\FuncCall( + return new FuncCall( new Name($functionName), [ $value, ] ); }, - 'ArrayHasKey' => function (Scope $scope, Arg $key, Arg $array): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('array_key_exists'), [$key, $array]); + 'ArrayHasKey' => static function (Scope $scope, Arg $key, Arg $array): FuncCall { + return new FuncCall(new Name('array_key_exists'), [$key, $array]); }, - 'ObjectHasAttribute' => function (Scope $scope, Arg $property, Arg $object): FuncCall { - return new \PhpParser\Node\Expr\FuncCall(new Name('property_exists'), [$object, $property]); + 'ObjectHasAttribute' => static function (Scope $scope, Arg $property, Arg $object): FuncCall { + return new FuncCall(new Name('property_exists'), [$object, $property]); }, ]; } diff --git a/src/Type/PHPUnit/InvocationMockerDynamicReturnTypeExtension.php b/src/Type/PHPUnit/InvocationMockerDynamicReturnTypeExtension.php index 51e2222..44764f6 100644 --- a/src/Type/PHPUnit/InvocationMockerDynamicReturnTypeExtension.php +++ b/src/Type/PHPUnit/InvocationMockerDynamicReturnTypeExtension.php @@ -5,10 +5,11 @@ use PhpParser\Node\Expr\MethodCall; use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; +use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\Type; use PHPUnit\Framework\MockObject\Builder\InvocationMocker; -class InvocationMockerDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension +class InvocationMockerDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { public function getClass(): string diff --git a/src/Type/PHPUnit/MockBuilderDynamicReturnTypeExtension.php b/src/Type/PHPUnit/MockBuilderDynamicReturnTypeExtension.php index d6ae40d..5390b11 100644 --- a/src/Type/PHPUnit/MockBuilderDynamicReturnTypeExtension.php +++ b/src/Type/PHPUnit/MockBuilderDynamicReturnTypeExtension.php @@ -5,10 +5,12 @@ use PhpParser\Node\Expr\MethodCall; use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; +use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\Type; use PHPUnit\Framework\MockObject\MockBuilder; +use function in_array; -class MockBuilderDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension +class MockBuilderDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { public function getClass(): string diff --git a/src/Type/PHPUnit/MockObjectDynamicReturnTypeExtension.php b/src/Type/PHPUnit/MockObjectDynamicReturnTypeExtension.php index 06e69b3..cb0b3a1 100644 --- a/src/Type/PHPUnit/MockObjectDynamicReturnTypeExtension.php +++ b/src/Type/PHPUnit/MockObjectDynamicReturnTypeExtension.php @@ -5,6 +5,7 @@ use PhpParser\Node\Expr\MethodCall; use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; +use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\IntersectionType; use PHPStan\Type\ObjectType; @@ -12,8 +13,11 @@ use PHPStan\Type\TypeWithClassName; use PHPUnit\Framework\MockObject\Builder\InvocationMocker; use PHPUnit\Framework\MockObject\MockObject; +use function array_filter; +use function array_values; +use function count; -class MockObjectDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension +class MockObjectDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { public function getClass(): string @@ -33,7 +37,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method return new ObjectType(InvocationMocker::class); } - $mockClasses = array_values(array_filter($type->getTypes(), function (Type $type): bool { + $mockClasses = array_values(array_filter($type->getTypes(), static function (Type $type): bool { return !$type instanceof TypeWithClassName || $type->getClassName() !== MockObject::class; })); diff --git a/tests/Rules/PHPUnit/AssertSameBooleanExpectedRuleTest.php b/tests/Rules/PHPUnit/AssertSameBooleanExpectedRuleTest.php index a96aa0a..916884c 100644 --- a/tests/Rules/PHPUnit/AssertSameBooleanExpectedRuleTest.php +++ b/tests/Rules/PHPUnit/AssertSameBooleanExpectedRuleTest.php @@ -3,11 +3,12 @@ namespace PHPStan\Rules\PHPUnit; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class AssertSameBooleanExpectedRuleTest extends \PHPStan\Testing\RuleTestCase +class AssertSameBooleanExpectedRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php b/tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php index dd96118..774223f 100644 --- a/tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php +++ b/tests/Rules/PHPUnit/AssertSameMethodDifferentTypesRuleTest.php @@ -4,11 +4,12 @@ use PHPStan\Rules\Comparison\ImpossibleCheckTypeMethodCallRule; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class AssertSameMethodDifferentTypesRuleTest extends \PHPStan\Testing\RuleTestCase +class AssertSameMethodDifferentTypesRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/PHPUnit/AssertSameNullExpectedRuleTest.php b/tests/Rules/PHPUnit/AssertSameNullExpectedRuleTest.php index 009a96d..c2a2242 100644 --- a/tests/Rules/PHPUnit/AssertSameNullExpectedRuleTest.php +++ b/tests/Rules/PHPUnit/AssertSameNullExpectedRuleTest.php @@ -3,11 +3,12 @@ namespace PHPStan\Rules\PHPUnit; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class AssertSameNullExpectedRuleTest extends \PHPStan\Testing\RuleTestCase +class AssertSameNullExpectedRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php b/tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php index e55d3e2..cc65b27 100644 --- a/tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php +++ b/tests/Rules/PHPUnit/AssertSameStaticMethodDifferentTypesRuleTest.php @@ -4,11 +4,12 @@ use PHPStan\Rules\Comparison\ImpossibleCheckTypeStaticMethodCallRule; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class AssertSameStaticMethodDifferentTypesRuleTest extends \PHPStan\Testing\RuleTestCase +class AssertSameStaticMethodDifferentTypesRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/PHPUnit/AssertSameWithCountRuleTest.php b/tests/Rules/PHPUnit/AssertSameWithCountRuleTest.php index 9a0caf9..32f564d 100644 --- a/tests/Rules/PHPUnit/AssertSameWithCountRuleTest.php +++ b/tests/Rules/PHPUnit/AssertSameWithCountRuleTest.php @@ -3,11 +3,12 @@ namespace PHPStan\Rules\PHPUnit; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class AssertSameWithCountRuleTest extends \PHPStan\Testing\RuleTestCase +class AssertSameWithCountRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/PHPUnit/MockMethodCallRuleTest.php b/tests/Rules/PHPUnit/MockMethodCallRuleTest.php index cd42678..605daae 100644 --- a/tests/Rules/PHPUnit/MockMethodCallRuleTest.php +++ b/tests/Rules/PHPUnit/MockMethodCallRuleTest.php @@ -3,11 +3,12 @@ namespace PHPStan\Rules\PHPUnit; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class MockMethodCallRuleTest extends \PHPStan\Testing\RuleTestCase +class MockMethodCallRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rules/PHPUnit/ShouldCallParentMethodsRuleTest.php b/tests/Rules/PHPUnit/ShouldCallParentMethodsRuleTest.php index 3f8d6e2..b378c67 100644 --- a/tests/Rules/PHPUnit/ShouldCallParentMethodsRuleTest.php +++ b/tests/Rules/PHPUnit/ShouldCallParentMethodsRuleTest.php @@ -3,11 +3,12 @@ namespace PHPStan\Rules\PHPUnit; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class ShouldCallParentMethodsRuleTest extends \PHPStan\Testing\RuleTestCase +class ShouldCallParentMethodsRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Type/PHPUnit/AssertFunctionTypeSpecifyingExtensionTest.php b/tests/Type/PHPUnit/AssertFunctionTypeSpecifyingExtensionTest.php index c32b9d0..f2a254d 100644 --- a/tests/Type/PHPUnit/AssertFunctionTypeSpecifyingExtensionTest.php +++ b/tests/Type/PHPUnit/AssertFunctionTypeSpecifyingExtensionTest.php @@ -3,6 +3,7 @@ namespace PHPStan\Type\PHPUnit; use PHPStan\Testing\TypeInferenceTestCase; +use function function_exists; class AssertFunctionTypeSpecifyingExtensionTest extends TypeInferenceTestCase { @@ -19,8 +20,6 @@ public function dataFileAsserts(): iterable /** * @dataProvider dataFileAsserts - * @param string $assertType - * @param string $file * @param mixed ...$args */ public function testFileAsserts( diff --git a/tests/Type/PHPUnit/AssertMethodTypeSpecifyingExtensionTest.php b/tests/Type/PHPUnit/AssertMethodTypeSpecifyingExtensionTest.php index 6f6a1fc..e1841e0 100644 --- a/tests/Type/PHPUnit/AssertMethodTypeSpecifyingExtensionTest.php +++ b/tests/Type/PHPUnit/AssertMethodTypeSpecifyingExtensionTest.php @@ -15,8 +15,6 @@ public function dataFileAsserts(): iterable /** * @dataProvider dataFileAsserts - * @param string $assertType - * @param string $file * @param mixed ...$args */ public function testFileAsserts(