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 152a898..95032a6 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,5 +1,6 @@ - + + @@ -8,59 +9,103 @@ src tests + - - + + - + + + + + - + - - - - - - + + + + + 10 - - - + + 10 + - - - + + + + + 10 + + + - - + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - tests/tmp + + tests/*/data diff --git a/src/Reflection/Nette/HtmlMethodReflection.php b/src/Reflection/Nette/HtmlMethodReflection.php index 781f736..36854c1 100644 --- a/src/Reflection/Nette/HtmlMethodReflection.php +++ b/src/Reflection/Nette/HtmlMethodReflection.php @@ -6,12 +6,14 @@ use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\FunctionVariant; use PHPStan\Reflection\MethodReflection; +use PHPStan\Reflection\ParametersAcceptor; use PHPStan\TrinaryLogic; use PHPStan\Type\Generic\TemplateTypeMap; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\VoidType; +use function substr; class HtmlMethodReflection implements MethodReflection { @@ -19,7 +21,7 @@ class HtmlMethodReflection implements MethodReflection /** @var string */ private $name; - /** @var \PHPStan\Reflection\ClassReflection */ + /** @var ClassReflection */ private $declaringClass; public function __construct(string $name, ClassReflection $declaringClass) @@ -44,7 +46,7 @@ public function isStatic(): bool } /** - * @return \PHPStan\Reflection\ParametersAcceptor[] + * @return ParametersAcceptor[] */ public function getVariants(): array { @@ -104,7 +106,7 @@ public function getDocComment(): ?string return null; } - public function hasSideEffects(): \PHPStan\TrinaryLogic + public function hasSideEffects(): TrinaryLogic { return TrinaryLogic::createYes(); } diff --git a/src/Reflection/Nette/HtmlPropertyReflection.php b/src/Reflection/Nette/HtmlPropertyReflection.php index 84bffbd..f82c39d 100644 --- a/src/Reflection/Nette/HtmlPropertyReflection.php +++ b/src/Reflection/Nette/HtmlPropertyReflection.php @@ -11,7 +11,7 @@ class HtmlPropertyReflection implements PropertyReflection { - /** @var \PHPStan\Reflection\ClassReflection */ + /** @var ClassReflection */ private $declaringClass; /** @var Type */ @@ -73,12 +73,12 @@ public function getDocComment(): ?string return null; } - public function getReadableType(): \PHPStan\Type\Type + public function getReadableType(): Type { return $this->type; } - public function getWritableType(): \PHPStan\Type\Type + public function getWritableType(): Type { return $this->type; } diff --git a/src/Reflection/Nette/NetteObjectClassReflectionExtension.php b/src/Reflection/Nette/NetteObjectClassReflectionExtension.php index 82cc846..dc4baa7 100644 --- a/src/Reflection/Nette/NetteObjectClassReflectionExtension.php +++ b/src/Reflection/Nette/NetteObjectClassReflectionExtension.php @@ -8,6 +8,15 @@ use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\PropertiesClassReflectionExtension; use PHPStan\Reflection\PropertyReflection; +use ReflectionClass; +use function array_merge; +use function array_unique; +use function array_values; +use function in_array; +use function sprintf; +use function strlen; +use function substr; +use function ucfirst; class NetteObjectClassReflectionExtension implements MethodsClassReflectionExtension, PropertiesClassReflectionExtension { @@ -29,7 +38,7 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa return $getterMethod->isPublic(); } - private function getMethodByProperty(ClassReflection $classReflection, string $propertyName): ?\PHPStan\Reflection\MethodReflection + private function getMethodByProperty(ClassReflection $classReflection, string $propertyName): ?MethodReflection { $getterMethodName = sprintf('get%s', ucfirst($propertyName)); if (!$classReflection->hasNativeMethod($getterMethodName)) { @@ -41,7 +50,7 @@ private function getMethodByProperty(ClassReflection $classReflection, string $p public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection { - /** @var \PHPStan\Reflection\MethodReflection $getterMethod */ + /** @var MethodReflection $getterMethod */ $getterMethod = $this->getMethodByProperty($classReflection, $propertyName); return new NetteObjectPropertyReflection($classReflection, ParametersAcceptorSelector::selectSingle($getterMethod->getVariants())->getReturnType()); } @@ -66,10 +75,10 @@ public function getMethod(ClassReflection $classReflection, string $methodName): } /** - * @param \ReflectionClass $class + * @param ReflectionClass $class * @return string[] */ - private function getTraitNames(\ReflectionClass $class): array + private function getTraitNames(ReflectionClass $class): array { $traitNames = $class->getTraitNames(); while ($class->getParentClass() !== false) { @@ -81,10 +90,9 @@ private function getTraitNames(\ReflectionClass $class): array } /** - * @param \ReflectionClass $class - * @return bool + * @param ReflectionClass $class */ - private function inheritsFromNetteObject(\ReflectionClass $class): bool + private function inheritsFromNetteObject(ReflectionClass $class): bool { $class = $class->getParentClass(); while ($class !== false) { diff --git a/src/Reflection/Nette/NetteObjectEventListenerMethodReflection.php b/src/Reflection/Nette/NetteObjectEventListenerMethodReflection.php index 2601799..d09fd96 100644 --- a/src/Reflection/Nette/NetteObjectEventListenerMethodReflection.php +++ b/src/Reflection/Nette/NetteObjectEventListenerMethodReflection.php @@ -6,6 +6,7 @@ use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\FunctionVariant; use PHPStan\Reflection\MethodReflection; +use PHPStan\Reflection\ParametersAcceptor; use PHPStan\TrinaryLogic; use PHPStan\Type\Generic\TemplateTypeMap; use PHPStan\Type\Type; @@ -17,7 +18,7 @@ class NetteObjectEventListenerMethodReflection implements MethodReflection /** @var string */ private $name; - /** @var \PHPStan\Reflection\ClassReflection */ + /** @var ClassReflection */ private $declaringClass; public function __construct(string $name, ClassReflection $declaringClass) @@ -47,7 +48,7 @@ public function isStatic(): bool } /** - * @return \PHPStan\Reflection\ParametersAcceptor[] + * @return ParametersAcceptor[] */ public function getVariants(): array { @@ -102,7 +103,7 @@ public function getDocComment(): ?string return null; } - public function hasSideEffects(): \PHPStan\TrinaryLogic + public function hasSideEffects(): TrinaryLogic { return TrinaryLogic::createYes(); } diff --git a/src/Reflection/Nette/NetteObjectPropertyReflection.php b/src/Reflection/Nette/NetteObjectPropertyReflection.php index 5978501..3515e10 100644 --- a/src/Reflection/Nette/NetteObjectPropertyReflection.php +++ b/src/Reflection/Nette/NetteObjectPropertyReflection.php @@ -10,10 +10,10 @@ class NetteObjectPropertyReflection implements PropertyReflection { - /** @var \PHPStan\Reflection\ClassReflection */ + /** @var ClassReflection */ private $declaringClass; - /** @var \PHPStan\Type\Type */ + /** @var Type */ private $type; public function __construct(ClassReflection $declaringClass, Type $type) @@ -72,12 +72,12 @@ public function getDocComment(): ?string return null; } - public function getReadableType(): \PHPStan\Type\Type + public function getReadableType(): Type { return $this->type; } - public function getWritableType(): \PHPStan\Type\Type + public function getWritableType(): Type { return $this->type; } diff --git a/src/Rule/Nette/DoNotExtendNetteObjectRule.php b/src/Rule/Nette/DoNotExtendNetteObjectRule.php index 4ad69a7..f914c32 100644 --- a/src/Rule/Nette/DoNotExtendNetteObjectRule.php +++ b/src/Rule/Nette/DoNotExtendNetteObjectRule.php @@ -6,14 +6,17 @@ use PhpParser\Node\Stmt\Class_; use PHPStan\Analyser\Scope; use PHPStan\Broker\Broker; +use PHPStan\Rules\Rule; +use function in_array; +use function sprintf; /** - * @implements \PHPStan\Rules\Rule + * @implements Rule */ -class DoNotExtendNetteObjectRule implements \PHPStan\Rules\Rule +class DoNotExtendNetteObjectRule implements Rule { - /** @var \PHPStan\Broker\Broker */ + /** @var Broker */ private $broker; public function __construct(Broker $broker) diff --git a/src/Rule/Nette/PresenterInjectedPropertiesExtension.php b/src/Rule/Nette/PresenterInjectedPropertiesExtension.php index c6e5644..c724066 100644 --- a/src/Rule/Nette/PresenterInjectedPropertiesExtension.php +++ b/src/Rule/Nette/PresenterInjectedPropertiesExtension.php @@ -4,6 +4,7 @@ use PHPStan\Reflection\PropertyReflection; use PHPStan\Rules\Properties\ReadWritePropertiesExtension; +use function strpos; class PresenterInjectedPropertiesExtension implements ReadWritePropertiesExtension { diff --git a/src/Rule/Nette/RethrowExceptionRule.php b/src/Rule/Nette/RethrowExceptionRule.php index c112df2..6edcdfa 100644 --- a/src/Rule/Nette/RethrowExceptionRule.php +++ b/src/Rule/Nette/RethrowExceptionRule.php @@ -7,13 +7,23 @@ use PhpParser\Node\Name; use PhpParser\Node\Stmt\TryCatch; use PHPStan\Analyser\Scope; +use PHPStan\Rules\Rule; use PHPStan\Type\ObjectType; use PHPStan\Type\TypeCombinator; +use Throwable; +use function array_map; +use function array_merge; +use function array_unique; +use function count; +use function is_array; +use function is_string; +use function sprintf; +use function strtolower; /** - * @implements \PHPStan\Rules\Rule + * @implements Rule */ -class RethrowExceptionRule implements \PHPStan\Rules\Rule +class RethrowExceptionRule implements Rule { /** @var array */ @@ -38,7 +48,7 @@ public function processNode(Node $node, Scope $scope): array foreach ($node->catches as $catch) { foreach ($catch->types as $type) { $typeClass = (string) $type; - if ($typeClass === 'Exception' || $typeClass === \Throwable::class) { + if ($typeClass === 'Exception' || $typeClass === Throwable::class) { $hasGeneralCatch = true; break 2; } @@ -57,7 +67,7 @@ public function processNode(Node $node, Scope $scope): array foreach ($exceptions as $exceptionName) { $exceptionType = new ObjectType($exceptionName); foreach ($node->catches as $catch) { - $caughtType = TypeCombinator::union(...array_map(function (Name $class): ObjectType { + $caughtType = TypeCombinator::union(...array_map(static function (Name $class): ObjectType { return new ObjectType((string) $class); }, $catch->types)); if (!$caughtType->isSuperTypeOf($exceptionType)->yes()) { @@ -83,8 +93,7 @@ public function processNode(Node $node, Scope $scope): array } /** - * @param \PHPStan\Analyser\Scope $scope - * @param \PhpParser\Node|\PhpParser\Node[]|scalar $node + * @param Node|Node[]|scalar $node * @return string[] */ private function getExceptionTypes(Scope $scope, $node): array diff --git a/src/Type/Nette/ComponentGetPresenterDynamicReturnTypeExtension.php b/src/Type/Nette/ComponentGetPresenterDynamicReturnTypeExtension.php index 0d82b96..83d090c 100644 --- a/src/Type/Nette/ComponentGetPresenterDynamicReturnTypeExtension.php +++ b/src/Type/Nette/ComponentGetPresenterDynamicReturnTypeExtension.php @@ -10,6 +10,7 @@ use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; +use function count; final class ComponentGetPresenterDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { diff --git a/src/Type/Nette/ComponentLookupDynamicReturnTypeExtension.php b/src/Type/Nette/ComponentLookupDynamicReturnTypeExtension.php index b7cd689..371ae56 100644 --- a/src/Type/Nette/ComponentLookupDynamicReturnTypeExtension.php +++ b/src/Type/Nette/ComponentLookupDynamicReturnTypeExtension.php @@ -10,6 +10,7 @@ use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; +use function count; final class ComponentLookupDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { diff --git a/src/Type/Nette/ComponentModelArrayAccessDynamicReturnTypeExtension.php b/src/Type/Nette/ComponentModelArrayAccessDynamicReturnTypeExtension.php index c29a3b0..b6fb610 100644 --- a/src/Type/Nette/ComponentModelArrayAccessDynamicReturnTypeExtension.php +++ b/src/Type/Nette/ComponentModelArrayAccessDynamicReturnTypeExtension.php @@ -10,6 +10,9 @@ use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\MixedType; use PHPStan\Type\Type; +use function count; +use function sprintf; +use function ucfirst; class ComponentModelArrayAccessDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { diff --git a/src/Type/Nette/ComponentModelDynamicReturnTypeExtension.php b/src/Type/Nette/ComponentModelDynamicReturnTypeExtension.php index 25e4cc0..691dc97 100644 --- a/src/Type/Nette/ComponentModelDynamicReturnTypeExtension.php +++ b/src/Type/Nette/ComponentModelDynamicReturnTypeExtension.php @@ -10,6 +10,9 @@ use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\MixedType; use PHPStan\Type\Type; +use function count; +use function sprintf; +use function ucfirst; class ComponentModelDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { diff --git a/src/Type/Nette/FormContainerUnsafeValuesDynamicReturnTypeExtension.php b/src/Type/Nette/FormContainerUnsafeValuesDynamicReturnTypeExtension.php index 95de88a..8ba79a9 100644 --- a/src/Type/Nette/FormContainerUnsafeValuesDynamicReturnTypeExtension.php +++ b/src/Type/Nette/FormContainerUnsafeValuesDynamicReturnTypeExtension.php @@ -14,6 +14,7 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\StringType; use PHPStan\Type\Type; +use function count; class FormContainerUnsafeValuesDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { diff --git a/src/Type/Nette/FormContainerValuesDynamicReturnTypeExtension.php b/src/Type/Nette/FormContainerValuesDynamicReturnTypeExtension.php index 997948d..a757f84 100644 --- a/src/Type/Nette/FormContainerValuesDynamicReturnTypeExtension.php +++ b/src/Type/Nette/FormContainerValuesDynamicReturnTypeExtension.php @@ -13,6 +13,7 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\StringType; use PHPStan\Type\Type; +use function count; final class FormContainerValuesDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { diff --git a/src/Type/Nette/FormsBaseControlDynamicReturnTypeExtension.php b/src/Type/Nette/FormsBaseControlDynamicReturnTypeExtension.php index bd338d1..cc6458d 100644 --- a/src/Type/Nette/FormsBaseControlDynamicReturnTypeExtension.php +++ b/src/Type/Nette/FormsBaseControlDynamicReturnTypeExtension.php @@ -6,9 +6,11 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParametersAcceptorSelector; +use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\Type; +use function count; -class FormsBaseControlDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension +class FormsBaseControlDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { public function getClass(): string diff --git a/src/Type/Nette/PresenterGetSessionReturnTypeExtension.php b/src/Type/Nette/PresenterGetSessionReturnTypeExtension.php index 3754b82..2101a73 100644 --- a/src/Type/Nette/PresenterGetSessionReturnTypeExtension.php +++ b/src/Type/Nette/PresenterGetSessionReturnTypeExtension.php @@ -9,6 +9,7 @@ use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use function count; final class PresenterGetSessionReturnTypeExtension implements DynamicMethodReturnTypeExtension { diff --git a/src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php b/src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php index 7f7a888..c201623 100644 --- a/src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php +++ b/src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php @@ -7,12 +7,15 @@ use PHPStan\Reflection\MethodReflection; use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\Constant\ConstantStringType; +use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; +use function count; +use function in_array; -class ServiceLocatorDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension +class ServiceLocatorDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { public function getClass(): string diff --git a/tests/NetteObjectChild.php b/tests/NetteObjectChild.php index 33e0354..6743d39 100644 --- a/tests/NetteObjectChild.php +++ b/tests/NetteObjectChild.php @@ -2,7 +2,9 @@ namespace PHPStan; -class NetteObjectChild extends \Nette\LegacyObject +use Nette\LegacyObject; + +class NetteObjectChild extends LegacyObject { /** @var callable[] */ diff --git a/tests/Reflection/Nette/HtmlClassReflectionExtensionTest.php b/tests/Reflection/Nette/HtmlClassReflectionExtensionTest.php index 201df25..3d30ba7 100644 --- a/tests/Reflection/Nette/HtmlClassReflectionExtensionTest.php +++ b/tests/Reflection/Nette/HtmlClassReflectionExtensionTest.php @@ -2,16 +2,20 @@ namespace PHPStan\Reflection\Nette; +use Nette\Utils\Html; +use PHPStan\Broker\Broker; use PHPStan\Reflection\ParametersAcceptorSelector; +use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\VerbosityLevel; +use stdClass; -class HtmlClassReflectionExtensionTest extends \PHPStan\Testing\PHPStanTestCase +class HtmlClassReflectionExtensionTest extends PHPStanTestCase { - /** @var \PHPStan\Broker\Broker */ + /** @var Broker */ private $broker; - /** @var \PHPStan\Reflection\Nette\HtmlClassReflectionExtension */ + /** @var HtmlClassReflectionExtension */ private $extension; protected function setUp(): void @@ -27,11 +31,11 @@ public function dataHasMethod(): array { return [ [ - \Nette\Utils\Html::class, + Html::class, true, ], [ - \stdClass::class, + stdClass::class, false, ], ]; @@ -39,8 +43,6 @@ public function dataHasMethod(): array /** * @dataProvider dataHasMethod - * @param string $className - * @param bool $result */ public function testHasMethod(string $className, bool $result): void { @@ -50,7 +52,7 @@ public function testHasMethod(string $className, bool $result): void public function testGetMethod(): void { - $classReflection = $this->broker->getClass(\Nette\Utils\Html::class); + $classReflection = $this->broker->getClass(Html::class); $methodReflection = $this->extension->getMethod($classReflection, 'href'); $parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants()); self::assertSame('href', $methodReflection->getName()); @@ -60,7 +62,7 @@ public function testGetMethod(): void self::assertTrue($parametersAcceptor->isVariadic()); self::assertFalse($methodReflection->isPrivate()); self::assertTrue($methodReflection->isPublic()); - self::assertSame(\Nette\Utils\Html::class, $parametersAcceptor->getReturnType()->describe(VerbosityLevel::value())); + self::assertSame(Html::class, $parametersAcceptor->getReturnType()->describe(VerbosityLevel::value())); } /** @@ -70,11 +72,11 @@ public function dataHasProperty(): array { return [ [ - \Nette\Utils\Html::class, + Html::class, true, ], [ - \stdClass::class, + stdClass::class, false, ], ]; @@ -82,8 +84,6 @@ public function dataHasProperty(): array /** * @dataProvider dataHasProperty - * @param string $className - * @param bool $result */ public function testHasProperty(string $className, bool $result): void { @@ -93,7 +93,7 @@ public function testHasProperty(string $className, bool $result): void public function testGetProperty(): void { - $classReflection = $this->broker->getClass(\Nette\Utils\Html::class); + $classReflection = $this->broker->getClass(Html::class); $propertyReflection = $this->extension->getProperty($classReflection, 'href'); self::assertSame($classReflection, $propertyReflection->getDeclaringClass()); self::assertFalse($propertyReflection->isStatic()); diff --git a/tests/Reflection/Nette/NetteObjectClassReflectionExtensionTest.php b/tests/Reflection/Nette/NetteObjectClassReflectionExtensionTest.php index af3addd..f83127d 100644 --- a/tests/Reflection/Nette/NetteObjectClassReflectionExtensionTest.php +++ b/tests/Reflection/Nette/NetteObjectClassReflectionExtensionTest.php @@ -2,13 +2,19 @@ namespace PHPStan\Reflection\Nette; -class NetteObjectClassReflectionExtensionTest extends \PHPStan\Testing\PHPStanTestCase +use PHPStan\Broker\Broker; +use PHPStan\SmartObjectChild; +use PHPStan\Testing\PHPStanTestCase; +use function class_exists; +use function sprintf; + +class NetteObjectClassReflectionExtensionTest extends PHPStanTestCase { - /** @var \PHPStan\Broker\Broker */ + /** @var Broker */ private $broker; - /** @var \PHPStan\Reflection\Nette\NetteObjectClassReflectionExtension */ + /** @var NetteObjectClassReflectionExtension */ private $extension; protected function setUp(): void @@ -24,12 +30,12 @@ public function dataHasMethod(): array { $data = []; $data[] = [ - \PHPStan\SmartObjectChild::class, + SmartObjectChild::class, 'onPublicEvent', true, ]; $data[] = [ - \PHPStan\SmartObjectChild::class, + SmartObjectChild::class, 'onProtectedEvent', false, ]; @@ -48,9 +54,6 @@ public function dataHasMethod(): array /** * @dataProvider dataHasMethod - * @param string $className - * @param string $method - * @param bool $result */ public function testHasMethod(string $className, string $method, bool $result): void { @@ -68,7 +71,7 @@ public function dataHasProperty(): array { $data = []; $data[] = [ - \PHPStan\SmartObjectChild::class, + SmartObjectChild::class, 'foo', false, ]; @@ -93,9 +96,6 @@ public function dataHasProperty(): array /** * @dataProvider dataHasProperty - * @param string $className - * @param string $property - * @param bool $result */ public function testHasProperty(string $className, string $property, bool $result): void { diff --git a/tests/Rule/Nette/DoNotExtendNetteObjectRuleTest.php b/tests/Rule/Nette/DoNotExtendNetteObjectRuleTest.php index 8de17dc..95461f0 100644 --- a/tests/Rule/Nette/DoNotExtendNetteObjectRuleTest.php +++ b/tests/Rule/Nette/DoNotExtendNetteObjectRuleTest.php @@ -3,11 +3,13 @@ namespace PHPStan\Rule\Nette; use PHPStan\Rules\Rule; +use PHPStan\Testing\RuleTestCase; +use function class_exists; /** - * @extends \PHPStan\Testing\RuleTestCase + * @extends RuleTestCase */ -class DoNotExtendNetteObjectRuleTest extends \PHPStan\Testing\RuleTestCase +class DoNotExtendNetteObjectRuleTest extends RuleTestCase { protected function getRule(): Rule diff --git a/tests/Rule/Nette/PresenterInjectedPropertiesExtensionTest.php b/tests/Rule/Nette/PresenterInjectedPropertiesExtensionTest.php index 6fb851e..e05b89e 100644 --- a/tests/Rule/Nette/PresenterInjectedPropertiesExtensionTest.php +++ b/tests/Rule/Nette/PresenterInjectedPropertiesExtensionTest.php @@ -2,7 +2,10 @@ namespace PHPStan\Rule\Nette; -class PresenterInjectedPropertiesExtensionTest extends \PHPStan\Testing\LevelsTestCase +use PHPStan\Testing\LevelsTestCase; +use const PHP_VERSION_ID; + +class PresenterInjectedPropertiesExtensionTest extends LevelsTestCase { public function dataTopics(): array diff --git a/tests/SmartObjectChild.php b/tests/SmartObjectChild.php index 6c30813..9873396 100644 --- a/tests/SmartObjectChild.php +++ b/tests/SmartObjectChild.php @@ -2,10 +2,12 @@ namespace PHPStan; +use Nette\SmartObject; + class SmartObjectChild { - use \Nette\SmartObject; + use SmartObject; /** @var callable[] */ public $onPublicEvent = []; diff --git a/tests/Type/Nette/FormContainerValuesDynamicReturnTypeExtensionTest.php b/tests/Type/Nette/FormContainerValuesDynamicReturnTypeExtensionTest.php index c1f69e3..fc76d79 100644 --- a/tests/Type/Nette/FormContainerValuesDynamicReturnTypeExtensionTest.php +++ b/tests/Type/Nette/FormContainerValuesDynamicReturnTypeExtensionTest.php @@ -2,6 +2,7 @@ namespace PHPStan\Type\Nette; +use Nette\Utils\ArrayHash; use PhpParser\Node\Arg; use PhpParser\Node\Expr; use PhpParser\Node\Expr\MethodCall; @@ -16,11 +17,12 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use PHPUnit\Framework\TestCase; -final class FormContainerValuesDynamicReturnTypeExtensionTest extends \PHPUnit\Framework\TestCase +final class FormContainerValuesDynamicReturnTypeExtensionTest extends TestCase { - /** @var \PHPStan\Type\Nette\FormContainerValuesDynamicReturnTypeExtension */ + /** @var FormContainerValuesDynamicReturnTypeExtension */ private $extension; protected function setUp(): void @@ -38,7 +40,7 @@ public function testParameterAsArray(): void TemplateTypeMap::createEmpty(), [], true, - new UnionType([new ArrayType(new MixedType(), new MixedType()), new IterableType(new MixedType(), new ObjectType(\Nette\Utils\ArrayHash::class))]) + new UnionType([new ArrayType(new MixedType(), new MixedType()), new IterableType(new MixedType(), new ObjectType(ArrayHash::class))]) )]); $scope = $this->createMock(Scope::class); @@ -63,7 +65,7 @@ public function testParameterAsArrayHash(): void $methodReflection = $this->createMock(MethodReflection::class); $methodReflection ->method('getVariants') - ->willReturn([new FunctionVariant(TemplateTypeMap::createEmpty(), TemplateTypeMap::createEmpty(), [], true, new UnionType([new ArrayType(new MixedType(), new MixedType()), new IterableType(new MixedType(), new ObjectType(\Nette\Utils\ArrayHash::class))]))]); + ->willReturn([new FunctionVariant(TemplateTypeMap::createEmpty(), TemplateTypeMap::createEmpty(), [], true, new UnionType([new ArrayType(new MixedType(), new MixedType()), new IterableType(new MixedType(), new ObjectType(ArrayHash::class))]))]); $scope = $this->createMock(Scope::class); $scope->method('getType')->willReturn(new ConstantBooleanType(false)); @@ -80,7 +82,7 @@ public function testParameterAsArrayHash(): void $resultType = $this->extension->getTypeFromMethodCall($methodReflection, $methodCall, $scope); self::assertInstanceOf(ObjectType::class, $resultType); - self::assertSame(\Nette\Utils\ArrayHash::class, $resultType->describe(VerbosityLevel::value())); + self::assertSame(ArrayHash::class, $resultType->describe(VerbosityLevel::value())); } public function testDefaultParameterIsArrayHash(): void @@ -88,7 +90,7 @@ public function testDefaultParameterIsArrayHash(): void $methodReflection = $this->createMock(MethodReflection::class); $methodReflection ->method('getVariants') - ->willReturn([new FunctionVariant(TemplateTypeMap::createEmpty(), TemplateTypeMap::createEmpty(), [], true, new UnionType([new ArrayType(new MixedType(), new MixedType()), new IterableType(new MixedType(), new ObjectType(\Nette\Utils\ArrayHash::class))]))]); + ->willReturn([new FunctionVariant(TemplateTypeMap::createEmpty(), TemplateTypeMap::createEmpty(), [], true, new UnionType([new ArrayType(new MixedType(), new MixedType()), new IterableType(new MixedType(), new ObjectType(ArrayHash::class))]))]); $scope = $this->createMock(Scope::class); $scope->method('getType')->willReturn(new ConstantBooleanType(false)); @@ -100,7 +102,7 @@ public function testDefaultParameterIsArrayHash(): void $resultType = $this->extension->getTypeFromMethodCall($methodReflection, $methodCall, $scope); self::assertInstanceOf(ObjectType::class, $resultType); - self::assertSame(\Nette\Utils\ArrayHash::class, $resultType->describe(VerbosityLevel::value())); + self::assertSame(ArrayHash::class, $resultType->describe(VerbosityLevel::value())); } }