diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index bec95c44..00000000 --- a/.editorconfig +++ /dev/null @@ -1,9 +0,0 @@ -root = true - -[*] -charset = utf-8 -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true -indent_style = space -indent_size = 4 diff --git a/build/target-repository/.github/workflows/standalone_install.yaml b/.github/workflows/standalone_install.yaml similarity index 100% rename from build/target-repository/.github/workflows/standalone_install.yaml rename to .github/workflows/standalone_install.yaml diff --git a/build/rector-downgrade-php.php b/build/rector-downgrade-php.php deleted file mode 100644 index 12c3a100..00000000 --- a/build/rector-downgrade-php.php +++ /dev/null @@ -1,14 +0,0 @@ -withDowngradeSets(php74: true) - ->withConfiguredRule(RemoveInterfacesRector::class, [ - ConfigurableRuleInterface::class, - ]) - ->withSkip(['*/Tests/*', '*/tests/*', __DIR__ . '/../../tests']); diff --git a/build/target-repository/.github/FUNDING.yml b/build/target-repository/.github/FUNDING.yml deleted file mode 100644 index f797866a..00000000 --- a/build/target-repository/.github/FUNDING.yml +++ /dev/null @@ -1,3 +0,0 @@ -# These are supported funding model platforms -github: tomasvotruba -custom: https://www.paypal.me/rectorphp diff --git a/build/target-repository/composer.json b/build/target-repository/composer.json deleted file mode 100644 index 8c134349..00000000 --- a/build/target-repository/composer.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "symplify/phpstan-rules", - "type": "phpstan-extension", - "description": "Set of Symplify rules for PHPStan", - "license": "MIT", - "require": { - "php": "^7.4|^8.0", - "phpstan/phpstan": "^2.0", - "nette/utils": "^3.2|^4.0", - "webmozart/assert": "^1.11" - }, - "autoload": { - "psr-4": { - "Symplify\\PHPStanRules\\": "src" - }, - "files": [ - "src/functions/fast-functions.php" - ] - }, - "extra": { - "phpstan": { - "includes": [ - "config/services/services.neon" - ] - } - } -} diff --git a/build/target-repository/phpstan-for-tests.neon b/build/target-repository/phpstan-for-tests.neon deleted file mode 100644 index 0d1b2a61..00000000 --- a/build/target-repository/phpstan-for-tests.neon +++ /dev/null @@ -1,9 +0,0 @@ -# this config is only for tests, it verifies all the rules are runnable -includes: - - vendor/symplify/phpstan-rules/config/symplify-rules.neon - -parameters: - level: 4 - - ignoreErrors: - - '#Class method "getName\(\)" is never used#' diff --git a/build/target-repository/tests/SomeClass.php.inc b/build/target-repository/tests/SomeClass.php.inc deleted file mode 100644 index 17ce8504..00000000 --- a/build/target-repository/tests/SomeClass.php.inc +++ /dev/null @@ -1,13 +0,0 @@ -name; - } -} diff --git a/composer.json b/composer.json index f4e48dd2..8c134349 100644 --- a/composer.json +++ b/composer.json @@ -4,24 +4,10 @@ "description": "Set of Symplify rules for PHPStan", "license": "MIT", "require": { - "php": ">=8.2", - "webmozart/assert": "^1.11", + "php": "^7.4|^8.0", "phpstan/phpstan": "^2.0", "nette/utils": "^3.2|^4.0", - "phpstan/phpdoc-parser": "^2.0" - }, - "require-dev": { - "nikic/php-parser": "^5.3", - "phpunit/phpunit": "^11.5", - "symfony/framework-bundle": "6.1.*", - "symplify/easy-coding-standard": "^12.5", - "tomasvotruba/class-leak": "^2.0", - "rector/rector": "^2.0.6", - "phpstan/extension-installer": "^1.4", - "symplify/phpstan-extensions": "^12.0", - "tomasvotruba/unused-public": "^2.0", - "tomasvotruba/type-coverage": "^2.0", - "shipmonk/composer-dependency-analyser": "^1.8" + "webmozart/assert": "^1.11" }, "autoload": { "psr-4": { @@ -31,26 +17,6 @@ "src/functions/fast-functions.php" ] }, - "autoload-dev": { - "psr-4": { - "Symplify\\PHPStanRules\\Tests\\": "tests" - }, - "classmap": [ - "stubs" - ] - }, - "config": { - "platform-check": false, - "allow-plugins": { - "phpstan/extension-installer": true - } - }, - "scripts": { - "check-cs": "vendor/bin/ecs check --ansi", - "fix-cs": "vendor/bin/ecs check --fix --ansi", - "phpstan": "vendor/bin/phpstan analyse --ansi", - "rector": "vendor/bin/rector process --dry-run --ansi" - }, "extra": { "phpstan": { "includes": [ diff --git a/ecs.php b/ecs.php deleted file mode 100644 index 7a5dab64..00000000 --- a/ecs.php +++ /dev/null @@ -1,18 +0,0 @@ -withPaths([ - __DIR__ . '/config', - __DIR__ . '/src', - __DIR__ . '/tests', - ]) - ->withRootFiles() - ->withPreparedSets(psr12: true, common: true) - ->withSkip([ - '*/Source/*', - '*/Fixture/*', - ]); diff --git a/full-tool-build.sh b/full-tool-build.sh deleted file mode 100644 index 3473d4fc..00000000 --- a/full-tool-build.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -# add patches -composer install --ansi - -# but skip dev dependencies -composer update --no-dev --ansi - -# remove tests and useless files, to make downgraded, scoped and deployed codebase as small as possible -rm -rf tests - -# downgrade with rector -mkdir rector-local -composer require rector/rector --working-dir rector-local -rector-local/vendor/bin/rector process bin src vendor --config build/rector-downgrade-php.php --ansi diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index 40b14680..00000000 --- a/phpstan.neon +++ /dev/null @@ -1,51 +0,0 @@ -includes: - - config/services/services.neon - - config/naming-rules.neon - -parameters: - treatPhpDocTypesAsCertain: false - errorFormat: symplify - - level: 8 - - # custom configuration - maximumIgnoredErrorCount: 10 - - paths: - - src - - config - - tests - - excludePaths: - # parallel - - packages/*-phpstan-printer/tests/*ToPhpCompiler/Fixture* - - # tests - - '*/tests/**/Source/*' - - */stubs/* - - */Fixture/* - - ignoreErrors: - - '#Method Symplify\\PHPStanRules\\Reflection\\ReflectionParser\:\:parseNativeClassReflection\(\) has parameter \$reflectionClass with generic class ReflectionClass but does not specify its types\: T#' - - # overly detailed - - '#Class Symplify\\PHPStanRules\\(.*?) extends generic class PHPStan\\Testing\\RuleTestCase but does not specify its types\: TRule#' - - '#Method Symplify\\PHPStanRules\\(.*?)\:\:getRule\(\) return type with generic interface PHPStan\\Rules\\Rule does not specify its types\: TNodeType#' - - '#Parameter \#2 \$expectedErrors of method PHPStan\\Testing\\RuleTestCase\:\:analyse\(\) expects list, (.*?) given#' - - # part of public contract - - '#Method Symplify\\PHPStanRules\\Tests\\Rules\\(.*?)\\(.*?)Test\:\:testRule\(\) has parameter \$(expectedError(.*?)|expectedErrors) with no value type specified in iterable type array#' - - # useful to have IDE know the types - - identifier: phpstanApi.instanceofType - - # fast effective check - - - message: '#Function is_a\(\) is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine#' - path: src/Rules/SeeAnnotationToTestRule.php - - # used in tests - - '#Public constant "Symplify\\PHPStanRules\\(.*?)Rule\:\:ERROR_MESSAGE" is never used#' - - - '#Although PHPStan\\Node\\InClassNode is covered by backward compatibility promise, this instanceof assumption might break because (.*?) not guaranteed to always stay the same#' - - '#PHPStan\\DependencyInjection\\NeonAdapter#' diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index d7da7477..00000000 --- a/phpunit.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - tests - tests/Rules/ClassNameRespectsParentSuffixRule/Fixture/ - tests/Rules/PHPUnit/PublicStaticDataProviderRule - - diff --git a/rector.php b/rector.php deleted file mode 100644 index 5ca0ff76..00000000 --- a/rector.php +++ /dev/null @@ -1,22 +0,0 @@ -withPhpSets() - ->withPreparedSets(codeQuality: true, deadCode: true, codingStyle: true, typeDeclarations: true, naming: true, privatization: true, earlyReturn: true, phpunitCodeQuality: true) - ->withPaths([__DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/tests']) - ->withRootFiles() - ->withImportNames() - ->withSkip([ - '*/Source/*', - '*/Fixture/*', - StringClassNameToClassConstantRector::class => [ - __DIR__ . '/src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php', - __DIR__ . '/tests/Naming/ClassToSuffixResolverTest.php', - __DIR__ . '/tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/PhpUpgradeImplementsMinPhpVersionInterfaceRuleTest.php', - ], - ]); diff --git a/src/Contract/PhpDocParser/PhpDocNodeVisitorInterface.php b/src/Contract/PhpDocParser/PhpDocNodeVisitorInterface.php index 3081f405..3e68fbfa 100644 --- a/src/Contract/PhpDocParser/PhpDocNodeVisitorInterface.php +++ b/src/Contract/PhpDocParser/PhpDocNodeVisitorInterface.php @@ -13,12 +13,15 @@ interface PhpDocNodeVisitorInterface { public function beforeTraverse(Node $node): void; - public function enterNode(Node $node): int|Node|null; + /** + * @return int|\PHPStan\PhpDocParser\Ast\Node|null + */ + public function enterNode(Node $node); /** * @return null|int|\PhpParser\Node|Node[] Replacement node (or special return) */ - public function leaveNode(Node $node): int|\PhpParser\Node|array|null; + public function leaveNode(Node $node); public function afterTraverse(Node $node): void; } diff --git a/src/Doctrine/DoctrineEntityDocumentAnalyser.php b/src/Doctrine/DoctrineEntityDocumentAnalyser.php index ae6fec32..67e8464d 100644 --- a/src/Doctrine/DoctrineEntityDocumentAnalyser.php +++ b/src/Doctrine/DoctrineEntityDocumentAnalyser.php @@ -7,7 +7,7 @@ use PHPStan\PhpDoc\ResolvedPhpDocBlock; use PHPStan\Reflection\ClassReflection; -final readonly class DoctrineEntityDocumentAnalyser +final class DoctrineEntityDocumentAnalyser { /** * @var string[] @@ -22,7 +22,7 @@ public static function isEntityClass(ClassReflection $classReflection): bool } foreach (self::ENTITY_DOCBLOCK_MARKERS as $entityDocBlockMarkers) { - if (str_contains($resolvedPhpDocBlock->getPhpDocString(), $entityDocBlockMarkers)) { + if (strpos($resolvedPhpDocBlock->getPhpDocString(), $entityDocBlockMarkers) !== false) { return true; } } diff --git a/src/Naming/ClassToSuffixResolver.php b/src/Naming/ClassToSuffixResolver.php index 0d294016..13703a04 100644 --- a/src/Naming/ClassToSuffixResolver.php +++ b/src/Naming/ClassToSuffixResolver.php @@ -13,7 +13,7 @@ final class ClassToSuffixResolver { public function resolveFromClass(string $parentClass): string { - $expectedSuffix = \str_contains($parentClass, '\\') ? (string) Strings::after( + $expectedSuffix = strpos($parentClass, '\\') !== false ? (string) Strings::after( $parentClass, '\\', -1 @@ -31,15 +31,15 @@ public function resolveFromClass(string $parentClass): string private function removeAbstractInterfacePrefixSuffix(string $parentType): string { - if (\str_ends_with($parentType, 'Interface')) { + if (substr_compare($parentType, 'Interface', -strlen('Interface')) === 0) { $parentType = substr($parentType, 0, -strlen('Interface')); } - if (\str_ends_with($parentType, 'Abstract')) { + if (substr_compare($parentType, 'Abstract', -strlen('Abstract')) === 0) { $parentType = substr($parentType, 0, -strlen('Abstract')); } - if (\str_starts_with($parentType, 'Abstract')) { + if (strncmp($parentType, 'Abstract', strlen('Abstract')) === 0) { return substr($parentType, strlen('Abstract')); } diff --git a/src/NodeAnalyzer/AttributeFinder.php b/src/NodeAnalyzer/AttributeFinder.php index ed0ebebf..a35793d6 100644 --- a/src/NodeAnalyzer/AttributeFinder.php +++ b/src/NodeAnalyzer/AttributeFinder.php @@ -13,15 +13,19 @@ final class AttributeFinder { - public function hasAttribute(ClassLike | ClassMethod | Property | Param $node, string $desiredAttributeClass): bool + /** + * @param \PhpParser\Node\Stmt\ClassLike|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $node + */ + public function hasAttribute($node, string $desiredAttributeClass): bool { return (bool) $this->findAttribute($node, $desiredAttributeClass); } /** * @return Attribute[] + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassLike|\PhpParser\Node\Param $node */ - private function findAttributes(ClassMethod | Property | ClassLike | Param $node): array + private function findAttributes($node): array { $attributes = []; @@ -32,8 +36,11 @@ private function findAttributes(ClassMethod | Property | ClassLike | Param $node return $attributes; } + /** + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassLike|\PhpParser\Node\Param $node + */ private function findAttribute( - ClassMethod | Property | ClassLike | Param $node, + $node, string $desiredAttributeClass ): ?Attribute { $attributes = $this->findAttributes($node); diff --git a/src/NodeAnalyzer/EnumAnalyzer.php b/src/NodeAnalyzer/EnumAnalyzer.php index 6d8d3adb..d1ab54aa 100644 --- a/src/NodeAnalyzer/EnumAnalyzer.php +++ b/src/NodeAnalyzer/EnumAnalyzer.php @@ -12,11 +12,15 @@ use PHPStan\Reflection\ClassReflection; use Symplify\PHPStanRules\PhpDoc\BarePhpDocParser; -final readonly class EnumAnalyzer +final class EnumAnalyzer { - public function __construct( - private BarePhpDocParser $barePhpDocParser - ) { + /** + * @readonly + */ + private BarePhpDocParser $barePhpDocParser; + public function __construct(BarePhpDocParser $barePhpDocParser) + { + $this->barePhpDocParser = $barePhpDocParser; } public function detect(Scope $scope, ClassLike $classLike): bool @@ -39,7 +43,7 @@ public function detect(Scope $scope, ClassLike $classLike): bool } // is in /Enum/ namespace - return str_contains($classReflection->getName(), '\\Enum\\'); + return strpos($classReflection->getName(), '\\Enum\\') !== false; } private function hasEnumAnnotation(Class_ $class): bool diff --git a/src/NodeAnalyzer/SymfonyRequiredMethodAnalyzer.php b/src/NodeAnalyzer/SymfonyRequiredMethodAnalyzer.php index 6a478a0f..4a001c8b 100644 --- a/src/NodeAnalyzer/SymfonyRequiredMethodAnalyzer.php +++ b/src/NodeAnalyzer/SymfonyRequiredMethodAnalyzer.php @@ -34,6 +34,6 @@ public static function detect(ClassMethod $classMethod): bool return false; } - return str_contains($docComment->getText(), '@required'); + return strpos($docComment->getText(), '@required') !== false; } } diff --git a/src/NodeFinder/TypeAwareNodeFinder.php b/src/NodeFinder/TypeAwareNodeFinder.php index 214007d9..06883549 100644 --- a/src/NodeFinder/TypeAwareNodeFinder.php +++ b/src/NodeFinder/TypeAwareNodeFinder.php @@ -10,8 +10,11 @@ /** * @todo remove after https://github.com/nikic/PHP-Parser/pull/869 is released */ -final readonly class TypeAwareNodeFinder +final class TypeAwareNodeFinder { + /** + * @readonly + */ private NodeFinder $nodeFinder; public function __construct() @@ -26,7 +29,7 @@ public function __construct() * @param class-string $type * @return TNode|null */ - public function findFirstInstanceOf(array|Node $nodes, string $type): ?Node + public function findFirstInstanceOf($nodes, string $type): ?Node { return $this->nodeFinder->findFirstInstanceOf($nodes, $type); } diff --git a/src/NodeTraverser/SimpleCallableNodeTraverser.php b/src/NodeTraverser/SimpleCallableNodeTraverser.php index 7bc87b63..daaf03bc 100644 --- a/src/NodeTraverser/SimpleCallableNodeTraverser.php +++ b/src/NodeTraverser/SimpleCallableNodeTraverser.php @@ -17,7 +17,7 @@ final class SimpleCallableNodeTraverser * @param callable(Node $node): (int|Node|null) $callable * @param Node|Node[]|null $nodes */ - public function traverseNodesWithCallable(Node | array | null $nodes, callable $callable): void + public function traverseNodesWithCallable($nodes, callable $callable): void { if ($nodes === null) { return; diff --git a/src/NodeVisitor/CallableNodeVisitor.php b/src/NodeVisitor/CallableNodeVisitor.php index 99c77419..86545660 100644 --- a/src/NodeVisitor/CallableNodeVisitor.php +++ b/src/NodeVisitor/CallableNodeVisitor.php @@ -25,7 +25,10 @@ public function __construct(callable $callable) $this->callable = $callable; } - public function enterNode(Node $node): int|Node|null + /** + * @return int|\PhpParser\Node|null + */ + public function enterNode(Node $node) { $originalNode = $node; diff --git a/src/NodeVisitor/HasScopedReturnNodeVisitor.php b/src/NodeVisitor/HasScopedReturnNodeVisitor.php index 58fc19d4..5481f321 100644 --- a/src/NodeVisitor/HasScopedReturnNodeVisitor.php +++ b/src/NodeVisitor/HasScopedReturnNodeVisitor.php @@ -13,12 +13,16 @@ final class HasScopedReturnNodeVisitor extends NodeVisitorAbstract { - public function __construct( - private bool $hasReturn = false - ) { + private bool $hasReturn = false; + public function __construct(bool $hasReturn = false) + { + $this->hasReturn = $hasReturn; } - public function enterNode(Node $node): int|Node|null + /** + * @return int|\PhpParser\Node|null + */ + public function enterNode(Node $node) { if ($node instanceof Closure) { return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; diff --git a/src/PHPUnit/DataProviderMethodResolver.php b/src/PHPUnit/DataProviderMethodResolver.php index 409fa996..765647fa 100644 --- a/src/PHPUnit/DataProviderMethodResolver.php +++ b/src/PHPUnit/DataProviderMethodResolver.php @@ -16,7 +16,7 @@ public static function match(ClassMethod $classMethod): ?string return null; } - if (! str_contains($docComment->getText(), '@dataProvider')) { + if (strpos($docComment->getText(), '@dataProvider') === false) { return null; } diff --git a/src/ParentClassMethodNodeResolver.php b/src/ParentClassMethodNodeResolver.php index 8cc260c3..6987a048 100644 --- a/src/ParentClassMethodNodeResolver.php +++ b/src/ParentClassMethodNodeResolver.php @@ -10,12 +10,20 @@ use PHPStan\Reflection\ReflectionProvider; use Symplify\PHPStanRules\Reflection\ReflectionParser; -final readonly class ParentClassMethodNodeResolver +final class ParentClassMethodNodeResolver { - public function __construct( - private ReflectionParser $reflectionParser, - private ReflectionProvider $reflectionProvider - ) { + /** + * @readonly + */ + private ReflectionParser $reflectionParser; + /** + * @readonly + */ + private ReflectionProvider $reflectionProvider; + public function __construct(ReflectionParser $reflectionParser, ReflectionProvider $reflectionProvider) + { + $this->reflectionParser = $reflectionParser; + $this->reflectionProvider = $reflectionProvider; } public function resolveParentClassMethod(Scope $scope, string $methodName): ?ClassMethod diff --git a/src/PhpDoc/BarePhpDocParser.php b/src/PhpDoc/BarePhpDocParser.php index 3caf70e3..9deeb653 100644 --- a/src/PhpDoc/BarePhpDocParser.php +++ b/src/PhpDoc/BarePhpDocParser.php @@ -12,12 +12,20 @@ use PHPStan\PhpDocParser\Parser\PhpDocParser; use PHPStan\PhpDocParser\Parser\TokenIterator; -final readonly class BarePhpDocParser +final class BarePhpDocParser { - public function __construct( - private PhpDocParser $phpDocParser, - private Lexer $lexer - ) { + /** + * @readonly + */ + private PhpDocParser $phpDocParser; + /** + * @readonly + */ + private Lexer $lexer; + public function __construct(PhpDocParser $phpDocParser, Lexer $lexer) + { + $this->phpDocParser = $phpDocParser; + $this->lexer = $lexer; } /** diff --git a/src/PhpDoc/PhpDocResolver.php b/src/PhpDoc/PhpDocResolver.php index 6975ff52..970a4886 100644 --- a/src/PhpDoc/PhpDocResolver.php +++ b/src/PhpDoc/PhpDocResolver.php @@ -10,11 +10,15 @@ use PHPStan\Reflection\ClassReflection; use PHPStan\Type\FileTypeMapper; -final readonly class PhpDocResolver +final class PhpDocResolver { - public function __construct( - private FileTypeMapper $fileTypeMapper - ) { + /** + * @readonly + */ + private FileTypeMapper $fileTypeMapper; + public function __construct(FileTypeMapper $fileTypeMapper) + { + $this->fileTypeMapper = $fileTypeMapper; } public function resolve(Scope $scope, ClassReflection $classReflection, Doc $doc): ResolvedPhpDocBlock diff --git a/src/PhpDocParser/PhpDocNodeVisitor/AbstractPhpDocNodeVisitor.php b/src/PhpDocParser/PhpDocNodeVisitor/AbstractPhpDocNodeVisitor.php index 773eea4e..c4a251ce 100644 --- a/src/PhpDocParser/PhpDocNodeVisitor/AbstractPhpDocNodeVisitor.php +++ b/src/PhpDocParser/PhpDocNodeVisitor/AbstractPhpDocNodeVisitor.php @@ -16,7 +16,10 @@ public function beforeTraverse(Node $node): void { } - public function enterNode(Node $node): int|Node|null + /** + * @return int|\PHPStan\PhpDocParser\Ast\Node|null + */ + public function enterNode(Node $node) { return null; } @@ -24,7 +27,7 @@ public function enterNode(Node $node): int|Node|null /** * @return null|int|\PhpParser\Node|Node[] Replacement node (or special return) */ - public function leaveNode(Node $node): int|\PhpParser\Node|array|null + public function leaveNode(Node $node) { return null; } diff --git a/src/PhpDocParser/PhpDocNodeVisitor/CallablePhpDocNodeVisitor.php b/src/PhpDocParser/PhpDocNodeVisitor/CallablePhpDocNodeVisitor.php index 3f6789dd..4f31dadd 100644 --- a/src/PhpDocParser/PhpDocNodeVisitor/CallablePhpDocNodeVisitor.php +++ b/src/PhpDocParser/PhpDocNodeVisitor/CallablePhpDocNodeVisitor.php @@ -8,6 +8,10 @@ final class CallablePhpDocNodeVisitor extends AbstractPhpDocNodeVisitor { + /** + * @readonly + */ + private ?string $docContent; /** * @var callable(Node, string|null): (int|null|Node) */ @@ -18,12 +22,16 @@ final class CallablePhpDocNodeVisitor extends AbstractPhpDocNodeVisitor */ public function __construct( callable $callable, - private readonly ?string $docContent + ?string $docContent ) { + $this->docContent = $docContent; $this->callable = $callable; } - public function enterNode(Node $node): int|Node|null + /** + * @return int|\PHPStan\PhpDocParser\Ast\Node|null + */ + public function enterNode(Node $node) { $callable = $this->callable; return $callable($node, $this->docContent); diff --git a/src/Reflection/ReflectionParser.php b/src/Reflection/ReflectionParser.php index 8889615f..d8452e91 100644 --- a/src/Reflection/ReflectionParser.php +++ b/src/Reflection/ReflectionParser.php @@ -20,21 +20,32 @@ final class ReflectionParser { + /** + * @readonly + */ + private TypeAwareNodeFinder $typeAwareNodeFinder; /** * @var array */ private array $classesByFilename = []; - private readonly Parser $parser; + /** + * @readonly + */ + private Parser $parser; public function __construct( - private readonly TypeAwareNodeFinder $typeAwareNodeFinder + TypeAwareNodeFinder $typeAwareNodeFinder ) { + $this->typeAwareNodeFinder = $typeAwareNodeFinder; $parserFactory = new ParserFactory(); $this->parser = $parserFactory->createForNewestSupportedVersion(); } - public function parseMethodReflection(ReflectionMethod|MethodReflection $reflectionMethod): ?ClassMethod + /** + * @param \ReflectionMethod|\PHPStan\Reflection\MethodReflection $reflectionMethod + */ + public function parseMethodReflection($reflectionMethod): ?ClassMethod { $classLike = $this->parseNativeClassReflection($reflectionMethod->getDeclaringClass()); if (! $classLike instanceof ClassLike) { @@ -57,7 +68,10 @@ public function parseClassReflection(ClassReflection $classReflection): ?ClassLi return $this->parseFilenameToClass($fileName); } - private function parseNativeClassReflection(ReflectionClass|ClassReflection $reflectionClass): ?ClassLike + /** + * @param \ReflectionClass|\PHPStan\Reflection\ClassReflection $reflectionClass + */ + private function parseNativeClassReflection($reflectionClass): ?ClassLike { $fileName = $reflectionClass->getFileName(); if ($fileName === false) { @@ -71,7 +85,7 @@ private function parseNativeClassReflection(ReflectionClass|ClassReflection $ref return $this->parseFilenameToClass($fileName); } - private function parseFilenameToClass(string $fileName): ClassLike|null + private function parseFilenameToClass(string $fileName): ?\PhpParser\Node\Stmt\ClassLike { if (isset($this->classesByFilename[$fileName])) { return $this->classesByFilename[$fileName]; @@ -87,7 +101,7 @@ private function parseFilenameToClass(string $fileName): ClassLike|null $nodeTraverser = new NodeTraverser(); $nodeTraverser->addVisitor(new NameResolver()); $nodeTraverser->traverse($stmts); - } catch (Throwable) { + } catch (Throwable $exception) { // not reachable return null; } diff --git a/src/Rules/ClassNameRespectsParentSuffixRule.php b/src/Rules/ClassNameRespectsParentSuffixRule.php index 230b5ace..d298846b 100644 --- a/src/Rules/ClassNameRespectsParentSuffixRule.php +++ b/src/Rules/ClassNameRespectsParentSuffixRule.php @@ -23,6 +23,10 @@ */ final class ClassNameRespectsParentSuffixRule implements Rule { + /** + * @readonly + */ + private ClassToSuffixResolver $classToSuffixResolver; /** * @var string */ @@ -52,9 +56,10 @@ final class ClassNameRespectsParentSuffixRule implements Rule * @param class-string[] $parentClasses */ public function __construct( - private readonly ClassToSuffixResolver $classToSuffixResolver, - array $parentClasses = [], + ClassToSuffixResolver $classToSuffixResolver, + array $parentClasses = [] ) { + $this->classToSuffixResolver = $classToSuffixResolver; $this->parentClasses = array_merge($parentClasses, self::DEFAULT_PARENT_CLASSES); } @@ -96,7 +101,7 @@ private function processClassNameAndShort(ClassReflection $classReflection): arr } $expectedSuffix = $this->classToSuffixResolver->resolveFromClass($parentClass); - if (\str_ends_with($classReflection->getName(), $expectedSuffix)) { + if (substr_compare($classReflection->getName(), $expectedSuffix, -strlen($expectedSuffix)) === 0) { return []; } diff --git a/src/Rules/Complexity/ForbiddenNewArgumentRule.php b/src/Rules/Complexity/ForbiddenNewArgumentRule.php index ba17cef9..fba0c601 100644 --- a/src/Rules/Complexity/ForbiddenNewArgumentRule.php +++ b/src/Rules/Complexity/ForbiddenNewArgumentRule.php @@ -16,14 +16,19 @@ /** * @implements Rule */ -final readonly class ForbiddenNewArgumentRule implements Rule +final class ForbiddenNewArgumentRule implements Rule { + /** + * @var string[] + * @readonly + */ + private array $forbiddenTypes; /** * @param string[] $forbiddenTypes */ - public function __construct( - private array $forbiddenTypes - ) { + public function __construct(array $forbiddenTypes) + { + $this->forbiddenTypes = $forbiddenTypes; } public function getNodeType(): string diff --git a/src/Rules/Doctrine/NoDocumentMockingRule.php b/src/Rules/Doctrine/NoDocumentMockingRule.php index 15af597d..558882f5 100644 --- a/src/Rules/Doctrine/NoDocumentMockingRule.php +++ b/src/Rules/Doctrine/NoDocumentMockingRule.php @@ -48,7 +48,7 @@ public function processNode(Node $node, Scope $scope): array $firstArg = $node->getArgs()[0]; $mockedClassType = $scope->getType($firstArg->value); foreach ($mockedClassType->getConstantStrings() as $constantString) { - if (! str_contains($constantString->getValue(), '\\Document\\')) { + if (strpos($constantString->getValue(), '\\Document\\') === false) { continue; } diff --git a/src/Rules/Doctrine/NoEntityMockingRule.php b/src/Rules/Doctrine/NoEntityMockingRule.php index 2857ad5e..0f69e32a 100644 --- a/src/Rules/Doctrine/NoEntityMockingRule.php +++ b/src/Rules/Doctrine/NoEntityMockingRule.php @@ -22,16 +22,20 @@ * * @implements Rule */ -final readonly class NoEntityMockingRule implements Rule +final class NoEntityMockingRule implements Rule { + /** + * @readonly + */ + private ReflectionProvider $reflectionProvider; /** * @var string */ public const ERROR_MESSAGE = 'Instead of entity or document mocking, create object directly to get better type support'; - public function __construct( - private ReflectionProvider $reflectionProvider - ) { + public function __construct(ReflectionProvider $reflectionProvider) + { + $this->reflectionProvider = $reflectionProvider; } public function getNodeType(): string diff --git a/src/Rules/Doctrine/NoGetRepositoryOutsideServiceRule.php b/src/Rules/Doctrine/NoGetRepositoryOutsideServiceRule.php index 0158ba54..928bc8d5 100644 --- a/src/Rules/Doctrine/NoGetRepositoryOutsideServiceRule.php +++ b/src/Rules/Doctrine/NoGetRepositoryOutsideServiceRule.php @@ -52,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array // dummy check $classReflection = $scope->getClassReflection(); - if (str_ends_with($classReflection->getName(), 'Repository')) { + if (substr_compare($classReflection->getName(), 'Repository', -strlen('Repository')) === 0) { return []; } diff --git a/src/Rules/Domain/RequireAttributeNamespaceRule.php b/src/Rules/Domain/RequireAttributeNamespaceRule.php index 5a2646e0..9ca20868 100644 --- a/src/Rules/Domain/RequireAttributeNamespaceRule.php +++ b/src/Rules/Domain/RequireAttributeNamespaceRule.php @@ -42,7 +42,7 @@ public function processNode(Node $node, Scope $scope): array // is class in "Attribute" namespace? $className = $classReflection->getName(); - if (str_contains($className, '\\Attribute\\')) { + if (strpos($className, '\\Attribute\\') !== false) { return []; } diff --git a/src/Rules/Domain/RequireExceptionNamespaceRule.php b/src/Rules/Domain/RequireExceptionNamespaceRule.php index 9a9282e9..492c6ec5 100644 --- a/src/Rules/Domain/RequireExceptionNamespaceRule.php +++ b/src/Rules/Domain/RequireExceptionNamespaceRule.php @@ -43,7 +43,7 @@ public function processNode(Node $node, Scope $scope): array // is class in "Exception" namespace? $className = $classReflection->getName(); - if (str_contains($className, '\\Exception\\')) { + if (strpos($className, '\\Exception\\') !== false) { return []; } diff --git a/src/Rules/Enum/RequireUniqueEnumConstantRule.php b/src/Rules/Enum/RequireUniqueEnumConstantRule.php index e5432218..f196f9e9 100644 --- a/src/Rules/Enum/RequireUniqueEnumConstantRule.php +++ b/src/Rules/Enum/RequireUniqueEnumConstantRule.php @@ -18,16 +18,20 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\Enum\RequireUniqueEnumConstantRule\RequireUniqueEnumConstantRuleTest */ -final readonly class RequireUniqueEnumConstantRule implements Rule +final class RequireUniqueEnumConstantRule implements Rule { + /** + * @readonly + */ + private EnumAnalyzer $enumAnalyzer; /** * @var string */ public const ERROR_MESSAGE = 'Enum constants "%s" are duplicated. Make them unique instead'; - public function __construct( - private EnumAnalyzer $enumAnalyzer - ) { + public function __construct(EnumAnalyzer $enumAnalyzer) + { + $this->enumAnalyzer = $enumAnalyzer; } public function getNodeType(): string diff --git a/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php b/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php index c1be7eaf..c3b29d67 100644 --- a/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php +++ b/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php @@ -75,11 +75,11 @@ public function processNode(Node $node, Scope $scope): array */ private function processInterfaceSuffix(Identifier $identifier): array { - if (str_ends_with($identifier->toString(), 'Interface')) { + if (substr_compare($identifier->toString(), 'Interface', -strlen('Interface')) === 0) { return []; } - if (str_ends_with($identifier->toString(), 'Trait')) { + if (substr_compare($identifier->toString(), 'Trait', -strlen('Trait')) === 0) { return [RuleErrorBuilder::message(self::TRAIT_ERROR_MESSAGE) ->identifier(RuleIdentifier::EXPLICIT_TRAIT_SUFFIX_NAME) ->build()]; @@ -95,7 +95,7 @@ private function processInterfaceSuffix(Identifier $identifier): array */ private function processTraitSuffix(Identifier $identifier): array { - if (str_ends_with($identifier->toString(), 'Trait')) { + if (substr_compare($identifier->toString(), 'Trait', -strlen('Trait')) === 0) { return []; } @@ -109,26 +109,26 @@ private function processTraitSuffix(Identifier $identifier): array */ private function processClassSuffix(Identifier $identifier, bool $isAbstract): array { - if ($isAbstract && ! str_starts_with($identifier->toString(), 'Abstract')) { + if ($isAbstract && strncmp($identifier->toString(), 'Abstract', strlen('Abstract')) !== 0) { return [RuleErrorBuilder::message(self::ABSTRACT_ERROR_MESSAGE) ->identifier(RuleIdentifier::EXPLICIT_ABSTRACT_PREFIX_NAME) ->build()]; } - if (! $isAbstract && str_starts_with($identifier->toString(), 'Abstract')) { + if (! $isAbstract && strncmp($identifier->toString(), 'Abstract', strlen('Abstract')) === 0) { return [RuleErrorBuilder::message(self::ABSTRACT_ERROR_MESSAGE) ->identifier(RuleIdentifier::EXPLICIT_ABSTRACT_PREFIX_NAME) ->build(), ]; } - if (str_ends_with($identifier->toString(), 'Interface')) { + if (substr_compare($identifier->toString(), 'Interface', -strlen('Interface')) === 0) { return [RuleErrorBuilder::message(self::INTERFACE_ERROR_MESSAGE) ->identifier(RuleIdentifier::EXPLICIT_INTERFACE_SUFFIX_NAME) ->build()]; } - if (str_ends_with($identifier->toString(), 'Trait')) { + if (substr_compare($identifier->toString(), 'Trait', -strlen('Trait')) === 0) { return [RuleErrorBuilder::message(self::TRAIT_ERROR_MESSAGE) ->identifier(RuleIdentifier::EXPLICIT_TRAIT_SUFFIX_NAME) ->build()]; diff --git a/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php b/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php index e808d13f..be67fabd 100644 --- a/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php +++ b/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php @@ -58,7 +58,7 @@ public function processNode(Node $node, Scope $scope): array // skip vendor based classes, as designed for extension $fileName = $parentClassReflection->getFileName(); - if (is_string($fileName) && str_contains($fileName, 'vendor')) { + if (is_string($fileName) && strpos($fileName, 'vendor') !== false) { return []; } diff --git a/src/Rules/ForbiddenFuncCallRule.php b/src/Rules/ForbiddenFuncCallRule.php index ca552b48..6d589d1d 100644 --- a/src/Rules/ForbiddenFuncCallRule.php +++ b/src/Rules/ForbiddenFuncCallRule.php @@ -22,8 +22,21 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenFuncCallRule\ForbiddenFuncCallRuleTest */ -final readonly class ForbiddenFuncCallRule implements Rule +final class ForbiddenFuncCallRule implements Rule { + /** + * @var array + * @readonly + */ + private array $forbiddenFunctions; + /** + * @readonly + */ + private ArrayStringAndFnMatcher $arrayStringAndFnMatcher; + /** + * @readonly + */ + private RequiredWithMessageFormatter $requiredWithMessageFormatter; /** * @var string */ @@ -32,11 +45,11 @@ /** * @param array $forbiddenFunctions */ - public function __construct( - private array $forbiddenFunctions, - private ArrayStringAndFnMatcher $arrayStringAndFnMatcher, - private RequiredWithMessageFormatter $requiredWithMessageFormatter, - ) { + public function __construct(array $forbiddenFunctions, ArrayStringAndFnMatcher $arrayStringAndFnMatcher, RequiredWithMessageFormatter $requiredWithMessageFormatter) + { + $this->forbiddenFunctions = $forbiddenFunctions; + $this->arrayStringAndFnMatcher = $arrayStringAndFnMatcher; + $this->requiredWithMessageFormatter = $requiredWithMessageFormatter; } public function getNodeType(): string diff --git a/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php b/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php index 1473b411..c23b864e 100644 --- a/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php +++ b/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php @@ -18,13 +18,16 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenMultipleClassLikeInOneFileRule\ForbiddenMultipleClassLikeInOneFileRuleTest */ -final readonly class ForbiddenMultipleClassLikeInOneFileRule implements Rule +final class ForbiddenMultipleClassLikeInOneFileRule implements Rule { /** * @var string */ public const ERROR_MESSAGE = 'Multiple class/interface/trait is not allowed in single file'; + /** + * @readonly + */ private NodeFinder $nodeFinder; public function __construct( diff --git a/src/Rules/ForbiddenNodeRule.php b/src/Rules/ForbiddenNodeRule.php index c6004574..5b49ed47 100644 --- a/src/Rules/ForbiddenNodeRule.php +++ b/src/Rules/ForbiddenNodeRule.php @@ -30,7 +30,10 @@ final class ForbiddenNodeRule implements Rule */ private array $forbiddenNodes = []; - private readonly Standard $standard; + /** + * @readonly + */ + private Standard $standard; /** * @param array> $forbiddenNodes diff --git a/src/Rules/MaximumIgnoredErrorCountRule.php b/src/Rules/MaximumIgnoredErrorCountRule.php index 75e4cf17..defc5c07 100644 --- a/src/Rules/MaximumIgnoredErrorCountRule.php +++ b/src/Rules/MaximumIgnoredErrorCountRule.php @@ -15,18 +15,26 @@ /** * @implements Rule */ -final readonly class MaximumIgnoredErrorCountRule implements Rule +final class MaximumIgnoredErrorCountRule implements Rule { + /** + * @readonly + */ + private int $limit = 0; /** * @var string */ public const ERROR_MESSAGE = "Ignored error count %d in phpstan.neon surpassed maximum limit %d.\nInstead of ignoring more errors, fix them to keep your codebase fit."; + /** + * @readonly + */ private NeonAdapter $neonAdapter; public function __construct( - private int $limit = 0 + int $limit = 0 ) { + $this->limit = $limit; $this->neonAdapter = new NeonAdapter(); } diff --git a/src/Rules/NoDynamicNameRule.php b/src/Rules/NoDynamicNameRule.php index abba040d..7297a3e6 100644 --- a/src/Rules/NoDynamicNameRule.php +++ b/src/Rules/NoDynamicNameRule.php @@ -24,16 +24,20 @@ * * @implements Rule */ -final readonly class NoDynamicNameRule implements Rule +final class NoDynamicNameRule implements Rule { + /** + * @readonly + */ + private CallableTypeAnalyzer $callableTypeAnalyzer; /** * @var string */ public const ERROR_MESSAGE = 'Use explicit names over dynamic ones'; - public function __construct( - private CallableTypeAnalyzer $callableTypeAnalyzer, - ) { + public function __construct(CallableTypeAnalyzer $callableTypeAnalyzer) + { + $this->callableTypeAnalyzer = $callableTypeAnalyzer; } public function getNodeType(): string diff --git a/src/Rules/NoReferenceRule.php b/src/Rules/NoReferenceRule.php index 21d69fd6..4849f9f5 100644 --- a/src/Rules/NoReferenceRule.php +++ b/src/Rules/NoReferenceRule.php @@ -26,16 +26,20 @@ * * @implements Rule */ -final readonly class NoReferenceRule implements Rule +final class NoReferenceRule implements Rule { + /** + * @readonly + */ + private ParentClassMethodNodeResolver $parentClassMethodNodeResolver; /** * @var string */ public const ERROR_MESSAGE = 'Use explicit return value over magic &reference'; - public function __construct( - private ParentClassMethodNodeResolver $parentClassMethodNodeResolver, - ) { + public function __construct(ParentClassMethodNodeResolver $parentClassMethodNodeResolver) + { + $this->parentClassMethodNodeResolver = $parentClassMethodNodeResolver; } public function getNodeType(): string @@ -69,8 +73,9 @@ public function processNode(Node $node, Scope $scope): array /** * @return list + * @param \PhpParser\Node\Stmt\Function_|\PhpParser\Node\Stmt\ClassMethod $functionLike */ - private function collectParamErrorMessages(Function_|ClassMethod $functionLike, Scope $scope): array + private function collectParamErrorMessages($functionLike, Scope $scope): array { // has parent method? → skip it as enforced by parent $methodName = (string) $functionLike->name; diff --git a/src/Rules/NoReturnSetterMethodRule.php b/src/Rules/NoReturnSetterMethodRule.php index 8defbbf3..f89243cb 100644 --- a/src/Rules/NoReturnSetterMethodRule.php +++ b/src/Rules/NoReturnSetterMethodRule.php @@ -21,8 +21,12 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\NoReturnSetterMethodRule\NoReturnSetterMethodRuleTest */ -final readonly class NoReturnSetterMethodRule implements Rule +final class NoReturnSetterMethodRule implements Rule { + /** + * @readonly + */ + private TypeAwareNodeFinder $typeAwareNodeFinder; /** * @var string */ @@ -34,9 +38,9 @@ */ private const SETTER_START_REGEX = '#^set[A-Z]#'; - public function __construct( - private TypeAwareNodeFinder $typeAwareNodeFinder - ) { + public function __construct(TypeAwareNodeFinder $typeAwareNodeFinder) + { + $this->typeAwareNodeFinder = $typeAwareNodeFinder; } /** diff --git a/src/Rules/PHPUnit/NoMockOnlyTestRule.php b/src/Rules/PHPUnit/NoMockOnlyTestRule.php index cedc05b8..f3682ab1 100644 --- a/src/Rules/PHPUnit/NoMockOnlyTestRule.php +++ b/src/Rules/PHPUnit/NoMockOnlyTestRule.php @@ -20,7 +20,7 @@ * * @implements Rule */ -final readonly class NoMockOnlyTestRule implements Rule +final class NoMockOnlyTestRule implements Rule { /** * @var string diff --git a/src/Rules/PHPUnit/NoTestMocksRule.php b/src/Rules/PHPUnit/NoTestMocksRule.php index 5542f57e..423b569c 100644 --- a/src/Rules/PHPUnit/NoTestMocksRule.php +++ b/src/Rules/PHPUnit/NoTestMocksRule.php @@ -16,8 +16,13 @@ /** * @implements Rule */ -final readonly class NoTestMocksRule implements Rule +final class NoTestMocksRule implements Rule { + /** + * @var string[] + * @readonly + */ + private array $allowedTypes = []; /** * @api * @var string @@ -32,9 +37,9 @@ /** * @param string[] $allowedTypes */ - public function __construct( - private array $allowedTypes = [] - ) { + public function __construct(array $allowedTypes = []) + { + $this->allowedTypes = $allowedTypes; } public function getNodeType(): string diff --git a/src/Rules/PreferredClassRule.php b/src/Rules/PreferredClassRule.php index 63b93866..40c3e412 100644 --- a/src/Rules/PreferredClassRule.php +++ b/src/Rules/PreferredClassRule.php @@ -24,8 +24,13 @@ * * @implements Rule */ -final readonly class PreferredClassRule implements Rule +final class PreferredClassRule implements Rule { + /** + * @var string[] + * @readonly + */ + private array $oldToPreferredClasses; /** * @var string */ @@ -34,9 +39,9 @@ /** * @param string[] $oldToPreferredClasses */ - public function __construct( - private array $oldToPreferredClasses - ) { + public function __construct(array $oldToPreferredClasses) + { + $this->oldToPreferredClasses = $oldToPreferredClasses; } public function processNode(Node $node, Scope $scope): array @@ -135,8 +140,9 @@ private function processClassName(string $className): array /** * @return list + * @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\Instanceof_ $node */ - private function processExprWithClass(StaticCall|Instanceof_ $node): array + private function processExprWithClass($node): array { if ($node->class instanceof Expr) { return []; diff --git a/src/Rules/PreventParentMethodVisibilityOverrideRule.php b/src/Rules/PreventParentMethodVisibilityOverrideRule.php index 673e886a..95efd852 100644 --- a/src/Rules/PreventParentMethodVisibilityOverrideRule.php +++ b/src/Rules/PreventParentMethodVisibilityOverrideRule.php @@ -18,16 +18,20 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\PreventParentMethodVisibilityOverrideRule\PreventParentMethodVisibilityOverrideRuleTest */ -final readonly class PreventParentMethodVisibilityOverrideRule implements Rule +final class PreventParentMethodVisibilityOverrideRule implements Rule { + /** + * @readonly + */ + private ReflectionProvider $reflectionProvider; /** * @var string */ public const ERROR_MESSAGE = 'Change "%s()" method visibility to "%s" to respect parent method visibility.'; - public function __construct( - private ReflectionProvider $reflectionProvider - ) { + public function __construct(ReflectionProvider $reflectionProvider) + { + $this->reflectionProvider = $reflectionProvider; } public function getNodeType(): string diff --git a/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php b/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php index 97e069ef..bedb4e0d 100644 --- a/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php +++ b/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php @@ -59,7 +59,10 @@ public function processNode(Node $node, Scope $scope): array ->build()]; } - private function resolveExprStaticType(FuncCall|Instanceof_ $node, Scope $scope): ?Type + /** + * @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\Instanceof_ $node + */ + private function resolveExprStaticType($node, Scope $scope): ?Type { if ($node instanceof Instanceof_) { return $this->resolveInstanceOfType($node, $scope); diff --git a/src/Rules/Rector/NoLeadingBackslashInNameRule.php b/src/Rules/Rector/NoLeadingBackslashInNameRule.php index 49010b2e..1f033acb 100644 --- a/src/Rules/Rector/NoLeadingBackslashInNameRule.php +++ b/src/Rules/Rector/NoLeadingBackslashInNameRule.php @@ -57,7 +57,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - if (! str_starts_with($argType->getValue(), '\\')) { + if (strncmp($argType->getValue(), '\\', strlen('\\')) !== 0) { return []; } diff --git a/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php b/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php index 955ae7bc..47d2faa0 100644 --- a/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php +++ b/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php @@ -60,7 +60,7 @@ public function processNode(Node $node, Scope $scope): array $configContent = FileSystem::read($configFilePath); // is rule registered? - if (str_contains($configContent, $className)) { + if (strpos($configContent, $className) !== false) { return []; } diff --git a/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php b/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php index 0541a7cc..2196698c 100644 --- a/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php +++ b/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php @@ -44,7 +44,7 @@ public function processNode(Node $node, Scope $scope): array { /** @var string $className */ $className = (string) $node->namespacedName; - if (! str_ends_with($className, 'Rector')) { + if (substr_compare($className, 'Rector', -strlen('Rector')) !== 0) { return []; } diff --git a/src/Rules/RequireAttributeNameRule.php b/src/Rules/RequireAttributeNameRule.php index c9cf139a..6d3f4e4e 100644 --- a/src/Rules/RequireAttributeNameRule.php +++ b/src/Rules/RequireAttributeNameRule.php @@ -43,7 +43,7 @@ public function processNode(Node $node, Scope $scope): array } // skip PHPUnit - if (str_starts_with($attributeName, 'PHPUnit\Framework\Attributes\\')) { + if (strncmp($attributeName, 'PHPUnit\Framework\Attributes\\', strlen('PHPUnit\Framework\Attributes\\')) === 0) { continue; } diff --git a/src/Rules/SeeAnnotationToTestRule.php b/src/Rules/SeeAnnotationToTestRule.php index 34ee037a..5f270749 100644 --- a/src/Rules/SeeAnnotationToTestRule.php +++ b/src/Rules/SeeAnnotationToTestRule.php @@ -24,8 +24,21 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\SeeAnnotationToTestRule\SeeAnnotationToTestRuleTest */ -final readonly class SeeAnnotationToTestRule implements Rule +final class SeeAnnotationToTestRule implements Rule { + /** + * @readonly + */ + private PhpDocResolver $phpDocResolver; + /** + * @readonly + */ + private SeePhpDocTagNodesFinder $seePhpDocTagNodesFinder; + /** + * @var string[] + * @readonly + */ + private array $requiredSeeTypes; /** * @var string */ @@ -34,11 +47,11 @@ /** * @param string[] $requiredSeeTypes */ - public function __construct( - private PhpDocResolver $phpDocResolver, - private SeePhpDocTagNodesFinder $seePhpDocTagNodesFinder, - private array $requiredSeeTypes - ) { + public function __construct(PhpDocResolver $phpDocResolver, SeePhpDocTagNodesFinder $seePhpDocTagNodesFinder, array $requiredSeeTypes) + { + $this->phpDocResolver = $phpDocResolver; + $this->seePhpDocTagNodesFinder = $seePhpDocTagNodesFinder; + $this->requiredSeeTypes = $requiredSeeTypes; } public function getNodeType(): string diff --git a/src/Rules/Symfony/NoAbstractControllerConstructorRule.php b/src/Rules/Symfony/NoAbstractControllerConstructorRule.php index b30c1be1..e983613f 100644 --- a/src/Rules/Symfony/NoAbstractControllerConstructorRule.php +++ b/src/Rules/Symfony/NoAbstractControllerConstructorRule.php @@ -46,7 +46,7 @@ public function processNode(Node $node, Scope $scope): array } $className = $node->name->toString(); - if (! str_ends_with($className, 'Controller')) { + if (substr_compare($className, 'Controller', -strlen('Controller')) !== 0) { return []; } diff --git a/src/Rules/Symfony/NoListenerWithoutContractRule.php b/src/Rules/Symfony/NoListenerWithoutContractRule.php index 621ebfae..11b811bd 100644 --- a/src/Rules/Symfony/NoListenerWithoutContractRule.php +++ b/src/Rules/Symfony/NoListenerWithoutContractRule.php @@ -61,7 +61,7 @@ public function processNode(Node $node, Scope $scope): array } $classReflection = $scope->getClassReflection(); - if (! str_ends_with($classReflection->getName(), 'Listener')) { + if (substr_compare($classReflection->getName(), 'Listener', -strlen('Listener')) !== 0) { return []; } diff --git a/src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php b/src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php index 59d1ca9e..7a69607c 100644 --- a/src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php +++ b/src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php @@ -53,10 +53,10 @@ public static function isControllerActionMethod(ClassMethod $classMethod): bool return false; } - if (str_contains($docComment->getText(), 'Symfony\Component\Routing\Annotation\Route')) { + if (strpos($docComment->getText(), 'Symfony\Component\Routing\Annotation\Route') !== false) { return true; } - return \str_contains($docComment->getText(), '@Route'); + return strpos($docComment->getText(), '@Route') !== false; } } diff --git a/src/Testing/PHPUnitTestAnalyser.php b/src/Testing/PHPUnitTestAnalyser.php index 152f4659..df4cefdc 100644 --- a/src/Testing/PHPUnitTestAnalyser.php +++ b/src/Testing/PHPUnitTestAnalyser.php @@ -38,6 +38,6 @@ public static function isTestClassMethod(ClassMethod $classMethod): bool return true; } - return str_starts_with($classMethod->name->toString(), 'test'); + return strncmp($classMethod->name->toString(), 'test', strlen('test')) === 0; } } diff --git a/src/ValueObject/Configuration/RequiredWithMessage.php b/src/ValueObject/Configuration/RequiredWithMessage.php index 408f5b9e..8d518121 100644 --- a/src/ValueObject/Configuration/RequiredWithMessage.php +++ b/src/ValueObject/Configuration/RequiredWithMessage.php @@ -4,12 +4,20 @@ namespace Symplify\PHPStanRules\ValueObject\Configuration; -final readonly class RequiredWithMessage +final class RequiredWithMessage { - public function __construct( - private string $required, - private ?string $message - ) { + /** + * @readonly + */ + private string $required; + /** + * @readonly + */ + private ?string $message; + public function __construct(string $required, ?string $message) + { + $this->required = $required; + $this->message = $message; } public function getRequired(): string diff --git a/tests/Naming/ClassToSuffixResolverTest.php b/tests/Naming/ClassToSuffixResolverTest.php deleted file mode 100644 index 43a2889b..00000000 --- a/tests/Naming/ClassToSuffixResolverTest.php +++ /dev/null @@ -1,38 +0,0 @@ -classToSuffixResolver = new ClassToSuffixResolver(); - } - - #[DataProvider('provideData')] - public function test(string $className, string $expectedSuffix): void - { - $resolvedSuffix = $this->classToSuffixResolver->resolveFromClass($className); - $this->assertSame($expectedSuffix, $resolvedSuffix); - } - - /** - * @return Iterator - */ - public static function provideData(): Iterator - { - yield ['Exception', 'Exception']; - yield ['Symfony\Component\Console\Command\Command', 'Command']; - yield [TestCase::class, 'Test']; - yield ['Symfony\Component\EventDispatcher\EventSubscriberInterface', 'EventSubscriber']; - } -} diff --git a/tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/NodeGetAttributeTypeExtensionTest.php b/tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/NodeGetAttributeTypeExtensionTest.php deleted file mode 100644 index 66d55b9a..00000000 --- a/tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/NodeGetAttributeTypeExtensionTest.php +++ /dev/null @@ -1,34 +0,0 @@ -assertFileAsserts($assertType, $file, ...$args); - } - - public static function dataAsserts(): Iterator - { - yield from self::gatherAssertTypes(__DIR__ . '/data/get_parent_node.php.inc'); - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/type_extension.neon']; - } -} diff --git a/tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/config/type_extension.neon b/tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/config/type_extension.neon deleted file mode 100644 index f8cef7ee..00000000 --- a/tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/config/type_extension.neon +++ /dev/null @@ -1,5 +0,0 @@ -services: - # $node->getAttribute($1) => Type|null by $1 - - - class: Symplify\PHPStanRules\ReturnTypeExtension\NodeGetAttributeTypeExtension - tags: [phpstan.broker.dynamicMethodReturnTypeExtension] diff --git a/tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/data/get_parent_node.php.inc b/tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/data/get_parent_node.php.inc deleted file mode 100644 index 4adb58ed..00000000 --- a/tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/data/get_parent_node.php.inc +++ /dev/null @@ -1,11 +0,0 @@ -getAttribute(AttributeKey::SCOPE); -\PHPStan\Testing\assertType('PHPStan\Analyser\Scope|null', $scope); diff --git a/tests/Rules/CheckRequiredInterfaceInContractNamespaceRule/CheckRequiredInterfaceInContractNamespaceRuleTest.php b/tests/Rules/CheckRequiredInterfaceInContractNamespaceRule/CheckRequiredInterfaceInContractNamespaceRuleTest.php deleted file mode 100644 index 11df6dc7..00000000 --- a/tests/Rules/CheckRequiredInterfaceInContractNamespaceRule/CheckRequiredInterfaceInContractNamespaceRuleTest.php +++ /dev/null @@ -1,42 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/Contract/SkipInterfaceInContract.php', []]; - yield [__DIR__ . '/Fixture/Illuminate/Contracts/View/View.php', []]; - yield [ - __DIR__ . '/Fixture/AnInterfaceNotInContract.php', - [[CheckRequiredInterfaceInContractNamespaceRule::ERROR_MESSAGE, 7]], ]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(CheckRequiredInterfaceInContractNamespaceRule::class); - } -} diff --git a/tests/Rules/CheckRequiredInterfaceInContractNamespaceRule/Fixture/AnInterfaceNotInContract.php b/tests/Rules/CheckRequiredInterfaceInContractNamespaceRule/Fixture/AnInterfaceNotInContract.php deleted file mode 100644 index 08a2d7dd..00000000 --- a/tests/Rules/CheckRequiredInterfaceInContractNamespaceRule/Fixture/AnInterfaceNotInContract.php +++ /dev/null @@ -1,10 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipCommand.php', []]; - yield [__DIR__ . '/Fixture/SkipSomeEventSubscriber.php', []]; - yield [__DIR__ . '/Fixture/SkipFixer.php', []]; - yield [__DIR__ . '/Fixture/SkipAnonymousClass.php', []]; - yield [__DIR__ . '/Fixture/SkipTest.php', []]; - yield [__DIR__ . '/Fixture/SkipAbstractTestCase.php', []]; - - $errorMessage = sprintf(ClassNameRespectsParentSuffixRule::ERROR_MESSAGE, 'Test'); - yield [__DIR__ . '/Fixture/NonTestSuffix.php', [[$errorMessage, 9]]]; - - $errorMessage = sprintf(ClassNameRespectsParentSuffixRule::ERROR_MESSAGE, 'Command'); - yield [__DIR__ . '/Fixture/SomeController.php', [[$errorMessage, 9]]]; - - $errorMessage = sprintf(ClassNameRespectsParentSuffixRule::ERROR_MESSAGE, 'EventSubscriber'); - yield [__DIR__ . '/Fixture/SomeEventSubscriberFalse.php', [[$errorMessage, 9]]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ClassNameRespectsParentSuffixRule::class); - } -} diff --git a/tests/Rules/ClassNameRespectsParentSuffixRule/Fixture/NonTestSuffix.php b/tests/Rules/ClassNameRespectsParentSuffixRule/Fixture/NonTestSuffix.php deleted file mode 100644 index 6da9fb6a..00000000 --- a/tests/Rules/ClassNameRespectsParentSuffixRule/Fixture/NonTestSuffix.php +++ /dev/null @@ -1,11 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipNormalArray.php', []]; - yield [__DIR__ . '/Fixture/ReturnCallable.php', [[ForbiddenArrayMethodCallRule::ERROR_MESSAGE, 11]]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ForbiddenArrayMethodCallRule::class); - } -} diff --git a/tests/Rules/Complexity/ForbiddenArrayMethodCallRule/config/configured_rule.neon b/tests/Rules/Complexity/ForbiddenArrayMethodCallRule/config/configured_rule.neon deleted file mode 100644 index 6273d331..00000000 --- a/tests/Rules/Complexity/ForbiddenArrayMethodCallRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\Complexity\ForbiddenArrayMethodCallRule diff --git a/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/Fixture/NonRepositoryUsingEntityManager.php b/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/Fixture/NonRepositoryUsingEntityManager.php deleted file mode 100644 index 3cd00306..00000000 --- a/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/Fixture/NonRepositoryUsingEntityManager.php +++ /dev/null @@ -1,20 +0,0 @@ -entityManager->getRepository(self::class); - } -} diff --git a/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/Fixture/SkipInRepository.php b/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/Fixture/SkipInRepository.php deleted file mode 100644 index 979da5f5..00000000 --- a/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/Fixture/SkipInRepository.php +++ /dev/null @@ -1,17 +0,0 @@ -entityManager->getRepository(SomeRandomEntity::class); - } -} diff --git a/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/NoGetRepositoryOutsideServiceRuleTest.php b/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/NoGetRepositoryOutsideServiceRuleTest.php deleted file mode 100644 index 5366d4c4..00000000 --- a/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/NoGetRepositoryOutsideServiceRuleTest.php +++ /dev/null @@ -1,38 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/NonRepositoryUsingEntityManager.php', [[ - NoGetRepositoryOutsideServiceRule::ERROR_MESSAGE, - 18, - ]]]; - - yield [__DIR__ . '/Fixture/SkipInRepository.php', []]; - } - - protected function getRule(): Rule - { - return new NoGetRepositoryOutsideServiceRule(); - } -} diff --git a/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/Source/SomeRandomEntity.php b/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/Source/SomeRandomEntity.php deleted file mode 100644 index 5c67f1b8..00000000 --- a/tests/Rules/Doctrine/NoGetRepositoryOutsideServiceRule/Source/SomeRandomEntity.php +++ /dev/null @@ -1,7 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SomeRepository.php', [[NoParentRepositoryRule::ERROR_MESSAGE, 9]]]; - } - - protected function getRule(): Rule - { - return new NoParentRepositoryRule(); - } -} diff --git a/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/Fixture/SkipNonFixtureClass.php b/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/Fixture/SkipNonFixtureClass.php deleted file mode 100644 index d8eecc5e..00000000 --- a/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/Fixture/SkipNonFixtureClass.php +++ /dev/null @@ -1,17 +0,0 @@ -getRepository('someEntity'); - - $alsoNotAllowed = $notAllowed->find(5); - } -} diff --git a/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/Fixture/SomeRepositoryCallInFixture.php b/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/Fixture/SomeRepositoryCallInFixture.php deleted file mode 100644 index d0e8e184..00000000 --- a/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/Fixture/SomeRepositoryCallInFixture.php +++ /dev/null @@ -1,18 +0,0 @@ -getRepository('someEntity'); - - $alsoNotAllowed = $notAllowed->find(5); - } -} diff --git a/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/NoRepositoryCallInDataFixtureRuleTest.php b/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/NoRepositoryCallInDataFixtureRuleTest.php deleted file mode 100644 index 07b4a66c..00000000 --- a/tests/Rules/Doctrine/NoRepositoryCallInDataFixtureRule/NoRepositoryCallInDataFixtureRuleTest.php +++ /dev/null @@ -1,38 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [ - __DIR__ . '/Fixture/SomeRepositoryCallInFixture.php', - [ - [NoRepositoryCallInDataFixtureRule::ERROR_MESSAGE, 14], - [NoRepositoryCallInDataFixtureRule::ERROR_MESSAGE, 16], - ], - ]; - - yield [__DIR__ . '/Fixture/SkipNonFixtureClass.php', []]; - } - - protected function getRule(): Rule - { - return new NoRepositoryCallInDataFixtureRule(); - } -} diff --git a/tests/Rules/Domain/RequireAttributeNamespaceRule/Fixture/Attribute/SkipCorrectAttribute.php b/tests/Rules/Domain/RequireAttributeNamespaceRule/Fixture/Attribute/SkipCorrectAttribute.php deleted file mode 100644 index bfc2a1dd..00000000 --- a/tests/Rules/Domain/RequireAttributeNamespaceRule/Fixture/Attribute/SkipCorrectAttribute.php +++ /dev/null @@ -1,10 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/MisslocatedAttribute.php', [[RequireAttributeNamespaceRule::ERROR_MESSAGE, 7]]]; - yield [__DIR__ . '/Fixture/Attribute/SkipCorrectAttribute.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(RequireAttributeNamespaceRule::class); - } -} diff --git a/tests/Rules/Domain/RequireAttributeNamespaceRule/config/configured_rule.neon b/tests/Rules/Domain/RequireAttributeNamespaceRule/config/configured_rule.neon deleted file mode 100644 index 5443e442..00000000 --- a/tests/Rules/Domain/RequireAttributeNamespaceRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\Domain\RequireAttributeNamespaceRule diff --git a/tests/Rules/Domain/RequireExceptionNamespaceRule/Fixture/Exception/SkipCorrectException.php b/tests/Rules/Domain/RequireExceptionNamespaceRule/Fixture/Exception/SkipCorrectException.php deleted file mode 100644 index c09aae43..00000000 --- a/tests/Rules/Domain/RequireExceptionNamespaceRule/Fixture/Exception/SkipCorrectException.php +++ /dev/null @@ -1,11 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/MisslocatedException.php', [[RequireExceptionNamespaceRule::ERROR_MESSAGE, 9]]]; - yield [__DIR__ . '/Fixture/Exception/SkipCorrectException.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(RequireExceptionNamespaceRule::class); - } -} diff --git a/tests/Rules/Domain/RequireExceptionNamespaceRule/config/configured_rule.neon b/tests/Rules/Domain/RequireExceptionNamespaceRule/config/configured_rule.neon deleted file mode 100644 index d344fc41..00000000 --- a/tests/Rules/Domain/RequireExceptionNamespaceRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\Domain\RequireExceptionNamespaceRule diff --git a/tests/Rules/Enum/RequireUniqueEnumConstantRule/Fixture/InvalidAnnotationEnum.php b/tests/Rules/Enum/RequireUniqueEnumConstantRule/Fixture/InvalidAnnotationEnum.php deleted file mode 100644 index a50ff5c8..00000000 --- a/tests/Rules/Enum/RequireUniqueEnumConstantRule/Fixture/InvalidAnnotationEnum.php +++ /dev/null @@ -1,15 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - $expectedErrorMessage = sprintf(RequireUniqueEnumConstantRule::ERROR_MESSAGE, 'yes'); - yield [__DIR__ . '/Fixture/InvalidEnum.php', [[$expectedErrorMessage, 8]]]; - yield [__DIR__ . '/Fixture/InvalidAnnotationEnum.php', [[$expectedErrorMessage, 8]]]; - - yield [__DIR__ . '/Fixture/SkipValidEnum.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(RequireUniqueEnumConstantRule::class); - } -} diff --git a/tests/Rules/Enum/RequireUniqueEnumConstantRule/config/configured_rule.neon b/tests/Rules/Enum/RequireUniqueEnumConstantRule/config/configured_rule.neon deleted file mode 100644 index 317a3057..00000000 --- a/tests/Rules/Enum/RequireUniqueEnumConstantRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\Enum\RequireUniqueEnumConstantRule diff --git a/tests/Rules/Explicit/ExplicitClassPrefixSuffixRule/ExplicitClassPrefixSuffixRuleTest.php b/tests/Rules/Explicit/ExplicitClassPrefixSuffixRule/ExplicitClassPrefixSuffixRuleTest.php deleted file mode 100644 index c4c6752b..00000000 --- a/tests/Rules/Explicit/ExplicitClassPrefixSuffixRule/ExplicitClassPrefixSuffixRuleTest.php +++ /dev/null @@ -1,60 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/CorrectInterface.php', []]; - yield [__DIR__ . '/Fixture/CorrectTrait.php', []]; - - yield [__DIR__ . '/Fixture/AbstractCorrectClass.php', []]; - yield [__DIR__ . '/Fixture/AbstractIncorrectClass.php', [ - [ExplicitClassPrefixSuffixRule::ABSTRACT_ERROR_MESSAGE, 5], - ]]; - - yield [__DIR__ . '/Fixture/WrongTraitSuffix.php', [ - [ExplicitClassPrefixSuffixRule::TRAIT_ERROR_MESSAGE, 5], - ]]; - - yield [__DIR__ . '/Fixture/WrongSuffixTrait.php', [ - [ExplicitClassPrefixSuffixRule::TRAIT_ERROR_MESSAGE, 5], - ]]; - - yield [__DIR__ . '/Fixture/WrongInterfaceSuffix.php', [ - [ExplicitClassPrefixSuffixRule::INTERFACE_ERROR_MESSAGE, 5], - ]]; - - yield [__DIR__ . '/Fixture/IncorrectClassInterface.php', [ - [ExplicitClassPrefixSuffixRule::INTERFACE_ERROR_MESSAGE, 5], - ]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ExplicitClassPrefixSuffixRule::class); - } -} diff --git a/tests/Rules/Explicit/ExplicitClassPrefixSuffixRule/Fixture/AbstractCorrectClass.php b/tests/Rules/Explicit/ExplicitClassPrefixSuffixRule/Fixture/AbstractCorrectClass.php deleted file mode 100644 index 12a71150..00000000 --- a/tests/Rules/Explicit/ExplicitClassPrefixSuffixRule/Fixture/AbstractCorrectClass.php +++ /dev/null @@ -1,8 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [ - __DIR__ . '/Fixture/ClassExtendingNonAbstractClass.php', - [[ForbiddenExtendOfNonAbstractClassRule::ERROR_MESSAGE, 9]], ]; - - yield [__DIR__ . '/Fixture/SkipVendorBasedClasses.php', []]; - yield [__DIR__ . '/Fixture/SkipClassExtendingAbstractClass.php', []]; - yield [__DIR__ . '/Fixture/SkipException.php', []]; - yield [__DIR__ . '/Fixture/SkipAnonymousExtend.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ForbiddenExtendOfNonAbstractClassRule::class); - } -} diff --git a/tests/Rules/ForbiddenExtendOfNonAbstractClassRule/Source/NonAbstractClass.php b/tests/Rules/ForbiddenExtendOfNonAbstractClassRule/Source/NonAbstractClass.php deleted file mode 100644 index 68a5b0ab..00000000 --- a/tests/Rules/ForbiddenExtendOfNonAbstractClassRule/Source/NonAbstractClass.php +++ /dev/null @@ -1,9 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - $errorMessage = sprintf(ForbiddenFuncCallRule::ERROR_MESSAGE, 'dump'); - yield [__DIR__ . '/Fixture/DebugFuncCall.php', [[$errorMessage, 11]]]; - - $errorMessage = sprintf(ForbiddenFuncCallRule::ERROR_MESSAGE, 'extract'); - yield [__DIR__ . '/Fixture/ExtractCall.php', [[$errorMessage, 11]]]; - - $errorMessage = sprintf(ForbiddenFuncCallRule::ERROR_MESSAGE, 'property_exists'); - yield [__DIR__ . '/Fixture/PropertyExists.php', [[$errorMessage, 11]]]; - - yield [__DIR__ . '/Fixture/SkipPropertyExistsOnXml.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ForbiddenFuncCallRule::class); - } -} diff --git a/tests/Rules/ForbiddenFuncCallRule/ForbiddenFuncCallRuleWithDeprecationsTest.php b/tests/Rules/ForbiddenFuncCallRule/ForbiddenFuncCallRuleWithDeprecationsTest.php deleted file mode 100644 index 649ce5c3..00000000 --- a/tests/Rules/ForbiddenFuncCallRule/ForbiddenFuncCallRuleWithDeprecationsTest.php +++ /dev/null @@ -1,55 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - // custom messages are defined in the config file - - $errorMessage = sprintf(ForbiddenFuncCallRule::ERROR_MESSAGE, 'dump'); - $errorMessage .= ': seems you missed some debugging function'; - yield [__DIR__ . '/Fixture/DebugFuncCall.php', [[$errorMessage, 11]]]; - - $errorMessage = sprintf(ForbiddenFuncCallRule::ERROR_MESSAGE, 'extract'); - $errorMessage .= ': you shouldn"t use this dynamic things'; - yield [__DIR__ . '/Fixture/ExtractCall.php', [[$errorMessage, 11]]]; - - // custom error defined as empty-string -> just prints the default message - $errorMessage = sprintf(ForbiddenFuncCallRule::ERROR_MESSAGE, 'property_exists'); - yield [__DIR__ . '/Fixture/PropertyExists.php', [[$errorMessage, 11]]]; - - yield [__DIR__ . '/Fixture/SkipPropertyExistsOnXml.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule_with_deprecations.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ForbiddenFuncCallRule::class); - } -} diff --git a/tests/Rules/ForbiddenFuncCallRule/config/configured_rule.neon b/tests/Rules/ForbiddenFuncCallRule/config/configured_rule.neon deleted file mode 100644 index bcc99b22..00000000 --- a/tests/Rules/ForbiddenFuncCallRule/config/configured_rule.neon +++ /dev/null @@ -1,13 +0,0 @@ -includes: - - ../../../config/included_services.neon - -services: - - - class: Symplify\PHPStanRules\Rules\ForbiddenFuncCallRule - tags: [phpstan.rules.rule] - arguments: - forbiddenFunctions: - - 'extract' - - 'dump' - - 'curl_*' - - 'property_exists' diff --git a/tests/Rules/ForbiddenFuncCallRule/config/configured_rule_with_deprecations.neon b/tests/Rules/ForbiddenFuncCallRule/config/configured_rule_with_deprecations.neon deleted file mode 100644 index 0442c12b..00000000 --- a/tests/Rules/ForbiddenFuncCallRule/config/configured_rule_with_deprecations.neon +++ /dev/null @@ -1,13 +0,0 @@ -includes: - - ../../../config/included_services.neon - -services: - - - class: Symplify\PHPStanRules\Rules\ForbiddenFuncCallRule - tags: [phpstan.rules.rule] - arguments: - forbiddenFunctions: - 'extract': 'you shouldn"t use this dynamic things' - 'dump': 'seems you missed some debugging function' - 'curl_*': 'we use a proper http client these days' - - 'property_exists' diff --git a/tests/Rules/ForbiddenMultipleClassLikeInOneFileRule/Fixture/MultipleClassLike.php b/tests/Rules/ForbiddenMultipleClassLikeInOneFileRule/Fixture/MultipleClassLike.php deleted file mode 100644 index ebe21580..00000000 --- a/tests/Rules/ForbiddenMultipleClassLikeInOneFileRule/Fixture/MultipleClassLike.php +++ /dev/null @@ -1,17 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipOneInterface.php', []]; - yield [__DIR__ . '/Fixture/SkipOneClassWithAnonymousClass.php', []]; - yield [__DIR__ . '/Fixture/SkipOneClass.php', []]; - yield [__DIR__ . '/Fixture/SkipOneTrait.php', []]; - - yield [ - __DIR__ . '/Fixture/MultipleClassLike.php', - [[ForbiddenMultipleClassLikeInOneFileRule::ERROR_MESSAGE, 3]], - ]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ForbiddenMultipleClassLikeInOneFileRule::class); - } -} diff --git a/tests/Rules/ForbiddenMultipleClassLikeInOneFileRule/config/configured_rule.neon b/tests/Rules/ForbiddenMultipleClassLikeInOneFileRule/config/configured_rule.neon deleted file mode 100644 index e641c8bf..00000000 --- a/tests/Rules/ForbiddenMultipleClassLikeInOneFileRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\ForbiddenMultipleClassLikeInOneFileRule diff --git a/tests/Rules/ForbiddenNodeRule/Fixture/EmptyCall.php b/tests/Rules/ForbiddenNodeRule/Fixture/EmptyCall.php deleted file mode 100644 index c65359f3..00000000 --- a/tests/Rules/ForbiddenNodeRule/Fixture/EmptyCall.php +++ /dev/null @@ -1,13 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - $errorMessage = sprintf(ForbiddenNodeRule::ERROR_MESSAGE, 'empty($value)'); - yield [__DIR__ . '/Fixture/EmptyCall.php', [[$errorMessage, 11]]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ForbiddenNodeRule::class); - } -} diff --git a/tests/Rules/ForbiddenNodeRule/config/configured_rule.neon b/tests/Rules/ForbiddenNodeRule/config/configured_rule.neon deleted file mode 100644 index 91fa6fd1..00000000 --- a/tests/Rules/ForbiddenNodeRule/config/configured_rule.neon +++ /dev/null @@ -1,14 +0,0 @@ -includes: - - ../../../config/included_services.neon - -services: - - - class: Symplify\PHPStanRules\Rules\ForbiddenNodeRule - tags: [phpstan.rules.rule] - arguments: - forbiddenNodes: - - PhpParser\Node\Expr\Empty_ - - PhpParser\Node\Stmt\Switch_ - - PhpParser\Node\Expr\ErrorSuppress - - - class: PhpParser\PrettyPrinter\Standard diff --git a/tests/Rules/ForbiddenStaticClassConstFetchRule/Fixture/SomeClassWithStaticConstFetch.php b/tests/Rules/ForbiddenStaticClassConstFetchRule/Fixture/SomeClassWithStaticConstFetch.php deleted file mode 100644 index 4caef847..00000000 --- a/tests/Rules/ForbiddenStaticClassConstFetchRule/Fixture/SomeClassWithStaticConstFetch.php +++ /dev/null @@ -1,13 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [ - __DIR__ . '/Fixture/SomeClassWithStaticConstFetch.php', - [[ForbiddenStaticClassConstFetchRule::ERROR_MESSAGE, 11]], - ]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ForbiddenStaticClassConstFetchRule::class); - } -} diff --git a/tests/Rules/ForbiddenStaticClassConstFetchRule/config/configured_rule.neon b/tests/Rules/ForbiddenStaticClassConstFetchRule/config/configured_rule.neon deleted file mode 100644 index 7edb61a5..00000000 --- a/tests/Rules/ForbiddenStaticClassConstFetchRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\ForbiddenStaticClassConstFetchRule diff --git a/tests/Rules/NoDynamicNameRule/Fixture/DynamicClassOnStaticPropertyFetch.php b/tests/Rules/NoDynamicNameRule/Fixture/DynamicClassOnStaticPropertyFetch.php deleted file mode 100644 index ae1b4f97..00000000 --- a/tests/Rules/NoDynamicNameRule/Fixture/DynamicClassOnStaticPropertyFetch.php +++ /dev/null @@ -1,12 +0,0 @@ -$value(); - } -} diff --git a/tests/Rules/NoDynamicNameRule/Fixture/DynamicPropertyFetch.php b/tests/Rules/NoDynamicNameRule/Fixture/DynamicPropertyFetch.php deleted file mode 100644 index f6ed6c91..00000000 --- a/tests/Rules/NoDynamicNameRule/Fixture/DynamicPropertyFetch.php +++ /dev/null @@ -1,12 +0,0 @@ -$value; - } -} diff --git a/tests/Rules/NoDynamicNameRule/Fixture/DynamicStaticMethodCallName.php b/tests/Rules/NoDynamicNameRule/Fixture/DynamicStaticMethodCallName.php deleted file mode 100644 index 3c137a47..00000000 --- a/tests/Rules/NoDynamicNameRule/Fixture/DynamicStaticMethodCallName.php +++ /dev/null @@ -1,13 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/DynamicConstantName.php', [[NoDynamicNameRule::ERROR_MESSAGE, 10]]]; - yield [__DIR__ . '/Fixture/DynamicMethodCallName.php', [[NoDynamicNameRule::ERROR_MESSAGE, 11]]]; - yield [__DIR__ . '/Fixture/DynamicStaticMethodCallName.php', [[NoDynamicNameRule::ERROR_MESSAGE, 11]]]; - yield [__DIR__ . '/Fixture/DynamicFuncCallName.php', [[NoDynamicNameRule::ERROR_MESSAGE, 11]]]; - - yield [__DIR__ . '/Fixture/DynamicPropertyFetch.php', [[NoDynamicNameRule::ERROR_MESSAGE, 10]]]; - yield [__DIR__ . '/Fixture/DynamicClassOnStaticPropertyFetch.php', [[NoDynamicNameRule::ERROR_MESSAGE, 10]]]; - - yield [__DIR__ . '/Fixture/SkipObjectClassOnPhp8.php', []]; - yield [__DIR__ . '/Fixture/SkipInvokable.php', []]; - yield [__DIR__ . '/Fixture/SkipClosure.php', []]; - yield [__DIR__ . '/Fixture/SkipCallable.php', []]; - yield [__DIR__ . '/Fixture/SkipNullableClosure.php', []]; - yield [__DIR__ . '/Fixture/SkipImmediatelyInvokedFunctionExpression.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(NoDynamicNameRule::class); - } -} diff --git a/tests/Rules/NoDynamicNameRule/Source/SomeInvokableClass.php b/tests/Rules/NoDynamicNameRule/Source/SomeInvokableClass.php deleted file mode 100644 index 670950b5..00000000 --- a/tests/Rules/NoDynamicNameRule/Source/SomeInvokableClass.php +++ /dev/null @@ -1,13 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SomeGlobalConst.php', [ - [NoGlobalConstRule::ERROR_MESSAGE, 7], - ]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(NoGlobalConstRule::class); - } -} diff --git a/tests/Rules/NoGlobalConstRule/config/configured_rule.neon b/tests/Rules/NoGlobalConstRule/config/configured_rule.neon deleted file mode 100644 index 4b1dd907..00000000 --- a/tests/Rules/NoGlobalConstRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\NoGlobalConstRule diff --git a/tests/Rules/NoReferenceRule/Fixture/AssignReference.php b/tests/Rules/NoReferenceRule/Fixture/AssignReference.php deleted file mode 100644 index ee683365..00000000 --- a/tests/Rules/NoReferenceRule/Fixture/AssignReference.php +++ /dev/null @@ -1,16 +0,0 @@ -args[1]; - $some = &$arg->value; - } -} diff --git a/tests/Rules/NoReferenceRule/Fixture/FunctionWithReference.php b/tests/Rules/NoReferenceRule/Fixture/FunctionWithReference.php deleted file mode 100644 index cdd88fec..00000000 --- a/tests/Rules/NoReferenceRule/Fixture/FunctionWithReference.php +++ /dev/null @@ -1,9 +0,0 @@ -run([&$argument]); - } - - private function run(array $array) - { - } -} diff --git a/tests/Rules/NoReferenceRule/Fixture/SkipParentMethodWithReference.php b/tests/Rules/NoReferenceRule/Fixture/SkipParentMethodWithReference.php deleted file mode 100644 index 597703d2..00000000 --- a/tests/Rules/NoReferenceRule/Fixture/SkipParentMethodWithReference.php +++ /dev/null @@ -1,14 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/MethodWithReference.php', [[NoReferenceRule::ERROR_MESSAGE, 9]]]; - yield [__DIR__ . '/Fixture/FunctionWithReference.php', [[NoReferenceRule::ERROR_MESSAGE, 7]]]; - yield [__DIR__ . '/Fixture/VariableReference.php', [[NoReferenceRule::ERROR_MESSAGE, 11]]]; - yield [__DIR__ . '/Fixture/ReferenceArgument.php', [[NoReferenceRule::ERROR_MESSAGE, 11]]]; - yield [__DIR__ . '/Fixture/AssignReference.php', [[NoReferenceRule::ERROR_MESSAGE, 14]]]; - - yield [__DIR__ . '/Fixture/SkipUseInReference.php', []]; - yield [__DIR__ . '/Fixture/SkipParentMethodWithReference.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(NoReferenceRule::class); - } -} diff --git a/tests/Rules/NoReferenceRule/Source/AbstractSomeParentClassWithReference.php b/tests/Rules/NoReferenceRule/Source/AbstractSomeParentClassWithReference.php deleted file mode 100644 index 35001a16..00000000 --- a/tests/Rules/NoReferenceRule/Source/AbstractSomeParentClassWithReference.php +++ /dev/null @@ -1,12 +0,0 @@ -name === 'hey') { - return; - } - - $this->name = $name; - } -} diff --git a/tests/Rules/NoReturnSetterMethodRule/Fixture/SkipRoute.php b/tests/Rules/NoReturnSetterMethodRule/Fixture/SkipRoute.php deleted file mode 100644 index c9433ae9..00000000 --- a/tests/Rules/NoReturnSetterMethodRule/Fixture/SkipRoute.php +++ /dev/null @@ -1,16 +0,0 @@ -name = $name; - } -} diff --git a/tests/Rules/NoReturnSetterMethodRule/Fixture/SomeSetterClass.php b/tests/Rules/NoReturnSetterMethodRule/Fixture/SomeSetterClass.php deleted file mode 100644 index 1f3c43ff..00000000 --- a/tests/Rules/NoReturnSetterMethodRule/Fixture/SomeSetterClass.php +++ /dev/null @@ -1,13 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SomeSetterClass.php', [[NoReturnSetterMethodRule::ERROR_MESSAGE, 9]]]; - - yield [__DIR__ . '/Fixture/SkipRoute.php', []]; - yield [__DIR__ . '/Fixture/SkipEmptyReturn.php', []]; - yield [__DIR__ . '/Fixture/SkipVoidSetter.php', []]; - yield [__DIR__ . '/Fixture/SkipSetUp.php', []]; - yield [__DIR__ . '/Fixture/SkipArrayFilter.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(NoReturnSetterMethodRule::class); - } -} diff --git a/tests/Rules/NoReturnSetterMethodRule/config/configured_rule.neon b/tests/Rules/NoReturnSetterMethodRule/config/configured_rule.neon deleted file mode 100644 index 21f69cee..00000000 --- a/tests/Rules/NoReturnSetterMethodRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\NoReturnSetterMethodRule diff --git a/tests/Rules/PHPUnit/NoEntityMockingRule/Fixture/MockingDocument.php b/tests/Rules/PHPUnit/NoEntityMockingRule/Fixture/MockingDocument.php deleted file mode 100644 index 0af640cc..00000000 --- a/tests/Rules/PHPUnit/NoEntityMockingRule/Fixture/MockingDocument.php +++ /dev/null @@ -1,14 +0,0 @@ -createMock(SomeDocument::class); - } -} diff --git a/tests/Rules/PHPUnit/NoEntityMockingRule/Fixture/MockingEntity.php b/tests/Rules/PHPUnit/NoEntityMockingRule/Fixture/MockingEntity.php deleted file mode 100644 index 05e1a506..00000000 --- a/tests/Rules/PHPUnit/NoEntityMockingRule/Fixture/MockingEntity.php +++ /dev/null @@ -1,14 +0,0 @@ -createMock(SomeEntity::class); - } -} diff --git a/tests/Rules/PHPUnit/NoEntityMockingRule/Fixture/SkipMockingOtherObject.php b/tests/Rules/PHPUnit/NoEntityMockingRule/Fixture/SkipMockingOtherObject.php deleted file mode 100644 index 38868913..00000000 --- a/tests/Rules/PHPUnit/NoEntityMockingRule/Fixture/SkipMockingOtherObject.php +++ /dev/null @@ -1,14 +0,0 @@ -createMock(SimpleObject::class); - } -} diff --git a/tests/Rules/PHPUnit/NoEntityMockingRule/NoEntityMockingRuleTest.php b/tests/Rules/PHPUnit/NoEntityMockingRule/NoEntityMockingRuleTest.php deleted file mode 100644 index 95ad55f9..00000000 --- a/tests/Rules/PHPUnit/NoEntityMockingRule/NoEntityMockingRuleTest.php +++ /dev/null @@ -1,41 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/MockingEntity.php', [[NoEntityMockingRule::ERROR_MESSAGE, 12]]]; - - yield [__DIR__ . '/Fixture/MockingDocument.php', [[NoEntityMockingRule::ERROR_MESSAGE, 12]]]; - - yield [__DIR__ . '/Fixture/SkipMockingOtherObject.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - $container = self::getContainer(); - return $container->getByType(NoEntityMockingRule::class); - } -} diff --git a/tests/Rules/PHPUnit/NoEntityMockingRule/Source/SimpleObject.php b/tests/Rules/PHPUnit/NoEntityMockingRule/Source/SimpleObject.php deleted file mode 100644 index b267523b..00000000 --- a/tests/Rules/PHPUnit/NoEntityMockingRule/Source/SimpleObject.php +++ /dev/null @@ -1,7 +0,0 @@ -firstClass = new FirstClass(); - - $this->anotherMock = $this->createMock(SecondClass::class); - } -} diff --git a/tests/Rules/PHPUnit/NoMockOnlyTestRule/Fixture/SomeTestWithOnlyMocks.php b/tests/Rules/PHPUnit/NoMockOnlyTestRule/Fixture/SomeTestWithOnlyMocks.php deleted file mode 100644 index 336dfebd..00000000 --- a/tests/Rules/PHPUnit/NoMockOnlyTestRule/Fixture/SomeTestWithOnlyMocks.php +++ /dev/null @@ -1,21 +0,0 @@ -someMock = $this->createMock(FirstClass::class); - - $this->anotherMock = $this->createMock(SecondClass::class); - } -} diff --git a/tests/Rules/PHPUnit/NoMockOnlyTestRule/NoMockOnlyTestRuleTest.php b/tests/Rules/PHPUnit/NoMockOnlyTestRule/NoMockOnlyTestRuleTest.php deleted file mode 100644 index 1f7e7f85..00000000 --- a/tests/Rules/PHPUnit/NoMockOnlyTestRule/NoMockOnlyTestRuleTest.php +++ /dev/null @@ -1,36 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SomeTestWithOnlyMocks.php', [[NoMockOnlyTestRule::ERROR_MESSAGE, 9]]]; - - yield [__DIR__ . '/Fixture/SkipTestWithClass.php', []]; - yield [__DIR__ . '/Fixture/SkipNoProperty.php', []]; - } - - protected function getRule(): Rule - { - return new NoMockOnlyTestRule(); - } -} diff --git a/tests/Rules/PHPUnit/NoMockOnlyTestRule/Source/FirstClass.php b/tests/Rules/PHPUnit/NoMockOnlyTestRule/Source/FirstClass.php deleted file mode 100644 index a473fa7b..00000000 --- a/tests/Rules/PHPUnit/NoMockOnlyTestRule/Source/FirstClass.php +++ /dev/null @@ -1,7 +0,0 @@ -createMock(SomeAllowedType::class); - } -} diff --git a/tests/Rules/PHPUnit/NoTestMocksRule/Fixture/SomeMocking.php b/tests/Rules/PHPUnit/NoTestMocksRule/Fixture/SomeMocking.php deleted file mode 100644 index 66df9c7d..00000000 --- a/tests/Rules/PHPUnit/NoTestMocksRule/Fixture/SomeMocking.php +++ /dev/null @@ -1,15 +0,0 @@ -createMock('SomeClass'); - } -} diff --git a/tests/Rules/PHPUnit/NoTestMocksRule/NoTestMocksRuleTest.php b/tests/Rules/PHPUnit/NoTestMocksRule/NoTestMocksRuleTest.php deleted file mode 100644 index 9cd4738a..00000000 --- a/tests/Rules/PHPUnit/NoTestMocksRule/NoTestMocksRuleTest.php +++ /dev/null @@ -1,45 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [ - __DIR__ . '/Fixture/SomeMocking.php', - [[sprintf(NoTestMocksRule::ERROR_MESSAGE, 'SomeClass'), 13]], - ]; - - yield [__DIR__ . '/Fixture/SkipApiMock.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [ - __DIR__ . '/config/configured_rule.neon', - ]; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(NoTestMocksRule::class); - } -} diff --git a/tests/Rules/PHPUnit/NoTestMocksRule/Source/SomeAllowedType.php b/tests/Rules/PHPUnit/NoTestMocksRule/Source/SomeAllowedType.php deleted file mode 100644 index 16c9e7fb..00000000 --- a/tests/Rules/PHPUnit/NoTestMocksRule/Source/SomeAllowedType.php +++ /dev/null @@ -1,7 +0,0 @@ -analyse($filePaths, $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [[__DIR__ . '/Fixture/SomeSimpleTest.php'], [ - [sprintf(PublicStaticDataProviderRule::STATIC_ERROR_MESSAGE, 'provideData'), 16], - [sprintf(PublicStaticDataProviderRule::PUBLIC_ERROR_MESSAGE, 'provideData'), 16], - ]]; - - yield [[__DIR__ . '/Fixture/SkipStaticTest.php'], []]; - } - - protected function getRule(): Rule - { - return new PublicStaticDataProviderRule(); - } -} diff --git a/tests/Rules/PreferredClassRule/Fixture/ClassExtendingOld.php b/tests/Rules/PreferredClassRule/Fixture/ClassExtendingOld.php deleted file mode 100644 index a3cf9d82..00000000 --- a/tests/Rules/PreferredClassRule/Fixture/ClassExtendingOld.php +++ /dev/null @@ -1,11 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - $errorMessage = sprintf(PreferredClassRule::ERROR_MESSAGE, NativeDateTime::class, DateTime::class); - yield [__DIR__ . '/Fixture/ClassUsingOld.php', [[$errorMessage, 13]]]; - yield [__DIR__ . '/Fixture/ClassExtendingOld.php', [[$errorMessage, 9]]]; - yield [__DIR__ . '/Fixture/ClassMethodParameterUsingOld.php', [[$errorMessage, 11]]]; - yield [__DIR__ . '/Fixture/SomeStaticCall.php', [[$errorMessage, 13]]]; - - $errorMessage = sprintf( - PreferredClassRule::ERROR_MESSAGE, - AbstractNotWhatYouWant::class, - SkipPreferredExtendingTheOldOne::class - ); - yield [__DIR__ . '/Fixture/InstanceOfName.php', [[$errorMessage, 13]]]; - - yield [__DIR__ . '/Fixture/SkipPreferredExtendingTheOldOne.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(PreferredClassRule::class); - } -} diff --git a/tests/Rules/PreferredClassRule/Source/AbstractNotWhatYouWant.php b/tests/Rules/PreferredClassRule/Source/AbstractNotWhatYouWant.php deleted file mode 100644 index e0bfb566..00000000 --- a/tests/Rules/PreferredClassRule/Source/AbstractNotWhatYouWant.php +++ /dev/null @@ -1,10 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - $errorMessage = sprintf(PreventParentMethodVisibilityOverrideRule::ERROR_MESSAGE, 'run', 'protected'); - yield [__DIR__ . '/Fixture/ClassWithOverridingVisibility.php', [[$errorMessage, 9]]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(PreventParentMethodVisibilityOverrideRule::class); - } -} diff --git a/tests/Rules/PreventParentMethodVisibilityOverrideRule/config/configured_rule.neon b/tests/Rules/PreventParentMethodVisibilityOverrideRule/config/configured_rule.neon deleted file mode 100644 index a8f51950..00000000 --- a/tests/Rules/PreventParentMethodVisibilityOverrideRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\PreventParentMethodVisibilityOverrideRule diff --git a/tests/Rules/Rector/NoClassReflectionStaticReflectionRule/Fixture/NewOnExternal.php b/tests/Rules/Rector/NoClassReflectionStaticReflectionRule/Fixture/NewOnExternal.php deleted file mode 100644 index e4865298..00000000 --- a/tests/Rules/Rector/NoClassReflectionStaticReflectionRule/Fixture/NewOnExternal.php +++ /dev/null @@ -1,15 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/NewOnExternal.php', [[NoClassReflectionStaticReflectionRule::ERROR_MESSAGE, 13]]]; - - yield [__DIR__ . '/Fixture/SkipAllowedType.php', []]; - yield [__DIR__ . '/Fixture/SkipNonReflectionNew.php', []]; - } - - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(NoClassReflectionStaticReflectionRule::class); - } -} diff --git a/tests/Rules/Rector/NoClassReflectionStaticReflectionRule/config/configured_rule.neon b/tests/Rules/Rector/NoClassReflectionStaticReflectionRule/config/configured_rule.neon deleted file mode 100644 index 03e55f2d..00000000 --- a/tests/Rules/Rector/NoClassReflectionStaticReflectionRule/config/configured_rule.neon +++ /dev/null @@ -1,2 +0,0 @@ -rules: - - Symplify\PHPStanRules\Rules\Rector\NoClassReflectionStaticReflectionRule diff --git a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/InstanceofWithType.php b/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/InstanceofWithType.php deleted file mode 100644 index c305dfd9..00000000 --- a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/InstanceofWithType.php +++ /dev/null @@ -1,19 +0,0 @@ -> - */ - private const BEFORE_TRAIT_TYPES = [TraitUse::class, Property::class, ClassMethod::class]; - - public function find(object $node): bool - { - foreach (self::BEFORE_TRAIT_TYPES as $beforeTraitType) { - if (is_a($node, $beforeTraitType, true)) { - return true; - } - } - - return false; - } -} diff --git a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipGenericNodeType.php b/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipGenericNodeType.php deleted file mode 100644 index f52533e5..00000000 --- a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipGenericNodeType.php +++ /dev/null @@ -1,21 +0,0 @@ - $type - */ - public function find(object $node, string $type): bool - { - if (is_a($node, $type, true)) { - return true; - } - - return true; - } -} diff --git a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipIsAGenericClassString.php b/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipIsAGenericClassString.php deleted file mode 100644 index 6ddee56e..00000000 --- a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipIsAGenericClassString.php +++ /dev/null @@ -1,26 +0,0 @@ - $type - * @return T|null - */ - public function findParentType(Node $parent, string $type) - { - do { - if (is_a($parent, $type, true)) { - return $parent; - } - } while ($parent = $parent->getAttribute('parent_node')); - - return null; - } -} diff --git a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipIsAsClassString.php b/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipIsAsClassString.php deleted file mode 100644 index cde6580d..00000000 --- a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipIsAsClassString.php +++ /dev/null @@ -1,20 +0,0 @@ - $desiredType - */ - private function hasOnlyStmtOfType(If_ $if, string $desiredType): bool - { - $stmts = $if->stmts; - return is_a($stmts[0], $desiredType); - } -} diff --git a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipPHPStanType.php b/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipPHPStanType.php deleted file mode 100644 index c5d00698..00000000 --- a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipPHPStanType.php +++ /dev/null @@ -1,15 +0,0 @@ - $type - */ - public function find(object $node, $type): bool - { - return is_a($node, $type, true); - } -} diff --git a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipReflection.php b/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipReflection.php deleted file mode 100644 index 3aa42a0f..00000000 --- a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/Fixture/SkipReflection.php +++ /dev/null @@ -1,19 +0,0 @@ -> - */ - private const COLLECTABLE_NODE_TYPES = [ - Class_::class, - Interface_::class, - ClassConst::class, - ClassConstFetch::class, - New_::class, - StaticCall::class, - MethodCall::class, - Array_::class, - Param::class, - ]; - - public function isCollectableNode(Node $node): bool - { - foreach (self::COLLECTABLE_NODE_TYPES as $collectableNodeType) { - /** @var class-string $collectableNodeType */ - if (is_a($node, $collectableNodeType, true)) { - return true; - } - } - - return false; - } -} diff --git a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/NoInstanceOfStaticReflectionRuleTest.php b/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/NoInstanceOfStaticReflectionRuleTest.php deleted file mode 100644 index a8ce9813..00000000 --- a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/NoInstanceOfStaticReflectionRuleTest.php +++ /dev/null @@ -1,51 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - $errorMessage = NoInstanceOfStaticReflectionRule::ERROR_MESSAGE; - yield [__DIR__ . '/Fixture/InstanceofWithType.php', [[$errorMessage, 13]]]; - - $errorMessage = NoInstanceOfStaticReflectionRule::ERROR_MESSAGE; - yield [__DIR__ . '/Fixture/IsAWithType.php', [[$errorMessage, 11]]]; - - yield [__DIR__ . '/Fixture/SkipAllowedType.php', []]; - yield [__DIR__ . '/Fixture/SkipGenericNodeType.php', []]; - yield [__DIR__ . '/Fixture/SkipIsAGenericClassString.php', []]; - yield [__DIR__ . '/Fixture/SkipIsAsClassString.php', []]; - yield [__DIR__ . '/Fixture/SkipArrayClassString.php', []]; - yield [__DIR__ . '/Fixture/SkipReflection.php', []]; - yield [__DIR__ . '/Fixture/SkipTypesArray.php', []]; - yield [__DIR__ . '/Fixture/SkipSymfony.php', []]; - yield [__DIR__ . '/Fixture/SkipPhpDocNode.php', []]; - yield [__DIR__ . '/Fixture/SkipPHPStanType.php', []]; - yield [__DIR__ . '/Fixture/SkipSelfType.php', []]; - } - - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(NoInstanceOfStaticReflectionRule::class); - } -} diff --git a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/config/configured_rule.neon b/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/config/configured_rule.neon deleted file mode 100644 index 4b1c9d43..00000000 --- a/tests/Rules/Rector/NoInstanceOfStaticReflectionRule/config/configured_rule.neon +++ /dev/null @@ -1,2 +0,0 @@ -rules: - - Symplify\PHPStanRules\Rules\Rector\NoInstanceOfStaticReflectionRule diff --git a/tests/Rules/Rector/NoLeadingBackslashInNameRule/Fixture/LeadingBackslashInName.php b/tests/Rules/Rector/NoLeadingBackslashInNameRule/Fixture/LeadingBackslashInName.php deleted file mode 100644 index df6f7f7a..00000000 --- a/tests/Rules/Rector/NoLeadingBackslashInNameRule/Fixture/LeadingBackslashInName.php +++ /dev/null @@ -1,15 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - $errorMessage = NoLeadingBackslashInNameRule::ERROR_MESSAGE; - yield [__DIR__ . '/Fixture/LeadingBackslashInName.php', [[$errorMessage, 13]]]; - - yield [__DIR__ . '/Fixture/SkipNoBackslash.php', []]; - yield [__DIR__ . '/Fixture/SkipUseFullyQualified.php', []]; - } - - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(NoLeadingBackslashInNameRule::class); - } -} diff --git a/tests/Rules/Rector/NoLeadingBackslashInNameRule/config/configured_rule.neon b/tests/Rules/Rector/NoLeadingBackslashInNameRule/config/configured_rule.neon deleted file mode 100644 index c6649019..00000000 --- a/tests/Rules/Rector/NoLeadingBackslashInNameRule/config/configured_rule.neon +++ /dev/null @@ -1,2 +0,0 @@ -rules: - - Symplify\PHPStanRules\Rules\Rector\NoLeadingBackslashInNameRule diff --git a/tests/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule/Fixture/DowngradePhp80/SomePhpFeature2Rector.php b/tests/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule/Fixture/DowngradePhp80/SomePhpFeature2Rector.php deleted file mode 100644 index 4b459894..00000000 --- a/tests/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule/Fixture/DowngradePhp80/SomePhpFeature2Rector.php +++ /dev/null @@ -1,21 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipSomePhpFeatureRector.php', []]; - yield [__DIR__ . '/Fixture/Php80/SkipConfigurableRector.php', []]; - - $errorMessage = sprintf( - PhpUpgradeDowngradeRegisteredInSetRule::ERROR_MESSAGE, - SomePhpFeatureRector::class, - 'php80.php' - ); - yield [__DIR__ . '/Fixture/Php80/SomePhpFeatureRector.php', [[$errorMessage, 10]]]; - - $errorMessage = sprintf( - PhpUpgradeDowngradeRegisteredInSetRule::ERROR_MESSAGE, - SomePhpFeature2Rector::class, - 'downgrade-php80.php' - ); - yield [__DIR__ . '/Fixture/DowngradePhp80/SomePhpFeature2Rector.php', [[$errorMessage, 10]]]; - } - - protected function getRule(): Rule - { - return new PhpUpgradeDowngradeRegisteredInSetRule(); - } -} diff --git a/tests/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule/Source/Set/downgrade-php80.php b/tests/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule/Source/Set/downgrade-php80.php deleted file mode 100644 index b1e0877e..00000000 --- a/tests/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule/Source/Set/downgrade-php80.php +++ /dev/null @@ -1,5 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipDowngradeRector.php', []]; - yield [__DIR__ . '/Fixture/SkipAlreadyImplementsMinPhpVersionRector.php', []]; - yield [__DIR__ . '/Fixture/SomePhpFeatureRector.php', [ - [ - sprintf( - PhpUpgradeImplementsMinPhpVersionInterfaceRule::ERROR_MESSAGE, - 'Rector\Php80\Rector\Class_\SomePhpFeatureRector', - ), - 7, - ], - ]]; - } - - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(PhpUpgradeImplementsMinPhpVersionInterfaceRule::class); - } -} diff --git a/tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/config/configured_rule.neon b/tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/config/configured_rule.neon deleted file mode 100644 index 38b70a18..00000000 --- a/tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/config/configured_rule.neon +++ /dev/null @@ -1,3 +0,0 @@ -rules: - - Symplify\PHPStanRules\Rules\Rector\PhpUpgradeImplementsMinPhpVersionInterfaceRule - diff --git a/tests/Rules/RequireAttributeNameRule/Fixture/MissingName.php b/tests/Rules/RequireAttributeNameRule/Fixture/MissingName.php deleted file mode 100644 index c0f10f7e..00000000 --- a/tests/Rules/RequireAttributeNameRule/Fixture/MissingName.php +++ /dev/null @@ -1,15 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/MissingName.php', [[RequireAttributeNameRule::ERROR_MESSAGE, 11]]]; - - yield [__DIR__ . '/Fixture/SkipCorrectName.php', []]; - yield [__DIR__ . '/Fixture/SkipDefaultName.php', []]; - yield [__DIR__ . '/Fixture/SkipPHPUnitAttributes.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(RequireAttributeNameRule::class); - } -} diff --git a/tests/Rules/RequireAttributeNameRule/config/configured_rule.neon b/tests/Rules/RequireAttributeNameRule/config/configured_rule.neon deleted file mode 100644 index 5d8751d9..00000000 --- a/tests/Rules/RequireAttributeNameRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\RequireAttributeNameRule diff --git a/tests/Rules/SeeAnnotationToTestRule/Fixture/RuleWithSee.php b/tests/Rules/SeeAnnotationToTestRule/Fixture/RuleWithSee.php deleted file mode 100644 index 6d7ce2b6..00000000 --- a/tests/Rules/SeeAnnotationToTestRule/Fixture/RuleWithSee.php +++ /dev/null @@ -1,24 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - $errorMessage = sprintf(SeeAnnotationToTestRule::ERROR_MESSAGE, RuleWithoutSee::class); - yield [__DIR__ . '/Fixture/RuleWithoutSee.php', [[$errorMessage, 12]]]; - - $errorMessage = sprintf(SeeAnnotationToTestRule::ERROR_MESSAGE, RuleWithSeeRandom::class); - yield [__DIR__ . '/Fixture/RuleWithSeeRandom.php', [[$errorMessage, 15]]]; - - yield [__DIR__ . '/Fixture/SkipDeprecatedRuleWithoutSee.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(SeeAnnotationToTestRule::class); - } -} diff --git a/tests/Rules/SeeAnnotationToTestRule/config/configured_rule.neon b/tests/Rules/SeeAnnotationToTestRule/config/configured_rule.neon deleted file mode 100644 index 6de88d79..00000000 --- a/tests/Rules/SeeAnnotationToTestRule/config/configured_rule.neon +++ /dev/null @@ -1,10 +0,0 @@ -includes: - - ../../../config/included_services.neon - -services: - - - class: Symplify\PHPStanRules\Rules\SeeAnnotationToTestRule - tags: [phpstan.rules.rule] - arguments: - requiredSeeTypes: - - PHPStan\Rules\Rule diff --git a/tests/Rules/Symfony/NoAbstractControllerConstructorRule/Fixture/SkipNonAbstractController.php b/tests/Rules/Symfony/NoAbstractControllerConstructorRule/Fixture/SkipNonAbstractController.php deleted file mode 100644 index 074f67ca..00000000 --- a/tests/Rules/Symfony/NoAbstractControllerConstructorRule/Fixture/SkipNonAbstractController.php +++ /dev/null @@ -1,12 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SomeAbstractController.php', [[ - NoAbstractControllerConstructorRule::ERROR_MESSAGE, - 7, - ]]]; - - yield [__DIR__ . '/Fixture/SkipNonAbstractController.php', []]; - } - - protected function getRule(): Rule - { - return new NoAbstractControllerConstructorRule(); - } -} diff --git a/tests/Rules/Symfony/NoListenerWithoutContractRule/Fixture/SkipDoctrineListener.php b/tests/Rules/Symfony/NoListenerWithoutContractRule/Fixture/SkipDoctrineListener.php deleted file mode 100644 index 2ba2a087..00000000 --- a/tests/Rules/Symfony/NoListenerWithoutContractRule/Fixture/SkipDoctrineListener.php +++ /dev/null @@ -1,10 +0,0 @@ -analyse($filePaths, $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [[__DIR__ . '/Fixture/SomeContractedListener.php'], []]; - yield [[__DIR__ . '/Fixture/SkipDoctrineListener.php'], []]; - - yield [[__DIR__ . '/Fixture/SomeBareListener.php'], [[ - NoListenerWithoutContractRule::ERROR_MESSAGE, - 5, - ]]]; - } - - protected function getRule(): Rule - { - return new NoListenerWithoutContractRule(); - } -} diff --git a/tests/Rules/Symfony/NoRequiredOutsideClassRule/Fixture/SomeClassUsingTrait.php b/tests/Rules/Symfony/NoRequiredOutsideClassRule/Fixture/SomeClassUsingTrait.php deleted file mode 100644 index 5926b233..00000000 --- a/tests/Rules/Symfony/NoRequiredOutsideClassRule/Fixture/SomeClassUsingTrait.php +++ /dev/null @@ -1,9 +0,0 @@ -analyse($filePaths, $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [[ - __DIR__ . '/Fixture/SomeClassUsingTrait.php', - __DIR__ . '/Fixture/TraitWithRequireAttribute.php', - __DIR__ . '/Fixture/TraitWithRequire.php', - ], [[NoRequiredOutsideClassRule::ERROR_MESSAGE, 9], [NoRequiredOutsideClassRule::ERROR_MESSAGE, 10]]]; - } - - protected function getRule(): Rule - { - return new NoRequiredOutsideClassRule(); - } -} diff --git a/tests/Rules/Symfony/RequireInvokableControllerRule/Fixture/MissnamedController.php b/tests/Rules/Symfony/RequireInvokableControllerRule/Fixture/MissnamedController.php deleted file mode 100644 index 7fb3f1d7..00000000 --- a/tests/Rules/Symfony/RequireInvokableControllerRule/Fixture/MissnamedController.php +++ /dev/null @@ -1,17 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [ - __DIR__ . '/Fixture/MissnamedRouteAttributeController.php', - [[RequireInvokableControllerRule::ERROR_MESSAGE, 12]], - ]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(RequireInvokableControllerRule::class); - } -} diff --git a/tests/Rules/Symfony/RequireInvokableControllerRule/RequireInvokableControllerRuleTest.php b/tests/Rules/Symfony/RequireInvokableControllerRule/RequireInvokableControllerRuleTest.php deleted file mode 100644 index cec5f9c9..00000000 --- a/tests/Rules/Symfony/RequireInvokableControllerRule/RequireInvokableControllerRuleTest.php +++ /dev/null @@ -1,48 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipInvokableController.php', []]; - yield [__DIR__ . '/Fixture/SkipRandomPublicMethodController.php', []]; - - yield [__DIR__ . '/Fixture/MissnamedController.php', [[RequireInvokableControllerRule::ERROR_MESSAGE, 14]]]; - yield [__DIR__ . '/Fixture/MultipleMethodsController.php', [ - [RequireInvokableControllerRule::ERROR_MESSAGE, 14], - [RequireInvokableControllerRule::ERROR_MESSAGE, 21], - ]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(RequireInvokableControllerRule::class); - } -} diff --git a/tests/Rules/Symfony/RequireInvokableControllerRule/config/configured_rule.neon b/tests/Rules/Symfony/RequireInvokableControllerRule/config/configured_rule.neon deleted file mode 100644 index ce4bf66b..00000000 --- a/tests/Rules/Symfony/RequireInvokableControllerRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../../../tests/config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\Symfony\RequireInvokableControllerRule diff --git a/tests/Rules/Symfony/RequiredOnlyInAbstractRule/Fixture/NonAbstractControllerWithRequired.php b/tests/Rules/Symfony/RequiredOnlyInAbstractRule/Fixture/NonAbstractControllerWithRequired.php deleted file mode 100644 index 2a3151fa..00000000 --- a/tests/Rules/Symfony/RequiredOnlyInAbstractRule/Fixture/NonAbstractControllerWithRequired.php +++ /dev/null @@ -1,15 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/NonAbstractControllerWithRequired.php', [[ - RequiredOnlyInAbstractRule::ERROR_MESSAGE, - 12, - ]]]; - - yield [__DIR__ . '/Fixture/SkipAbstractClass.php', []]; - yield [__DIR__ . '/Fixture/SkipParentDocumentRepository.php', []]; - } - - protected function getRule(): Rule - { - return new RequiredOnlyInAbstractRule(); - } -} diff --git a/tests/Rules/Symfony/SingleArgEventDispatchRule/Fixture/ReportEventDispatcher.php b/tests/Rules/Symfony/SingleArgEventDispatchRule/Fixture/ReportEventDispatcher.php deleted file mode 100644 index 910c2a5b..00000000 --- a/tests/Rules/Symfony/SingleArgEventDispatchRule/Fixture/ReportEventDispatcher.php +++ /dev/null @@ -1,13 +0,0 @@ -dispatch('one', 'two'); - } -} diff --git a/tests/Rules/Symfony/SingleArgEventDispatchRule/Fixture/SkipSingleDispatch.php b/tests/Rules/Symfony/SingleArgEventDispatchRule/Fixture/SkipSingleDispatch.php deleted file mode 100644 index c645737f..00000000 --- a/tests/Rules/Symfony/SingleArgEventDispatchRule/Fixture/SkipSingleDispatch.php +++ /dev/null @@ -1,13 +0,0 @@ -dispatch('one'); - } -} diff --git a/tests/Rules/Symfony/SingleArgEventDispatchRule/Fixture/SkipUnrelatedDispatch.php b/tests/Rules/Symfony/SingleArgEventDispatchRule/Fixture/SkipUnrelatedDispatch.php deleted file mode 100644 index 68dedc66..00000000 --- a/tests/Rules/Symfony/SingleArgEventDispatchRule/Fixture/SkipUnrelatedDispatch.php +++ /dev/null @@ -1,13 +0,0 @@ -dispatch('one', 'two'); - } -} diff --git a/tests/Rules/Symfony/SingleArgEventDispatchRule/SingleArgEventDispatchRuleTest.php b/tests/Rules/Symfony/SingleArgEventDispatchRule/SingleArgEventDispatchRuleTest.php deleted file mode 100644 index 485f7b9c..00000000 --- a/tests/Rules/Symfony/SingleArgEventDispatchRule/SingleArgEventDispatchRuleTest.php +++ /dev/null @@ -1,33 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/ReportEventDispatcher.php', [[SingleArgEventDispatchRule::ERROR_MESSAGE, 11]]]; - - yield [__DIR__ . '/Fixture/SkipSingleDispatch.php', []]; - yield [__DIR__ . '/Fixture/SkipUnrelatedDispatch.php', []]; - } - - protected function getRule(): Rule - { - return new SingleArgEventDispatchRule(); - } -} diff --git a/tests/Rules/Symfony/SingleArgEventDispatchRule/Source/NotEventDispatcher.php b/tests/Rules/Symfony/SingleArgEventDispatchRule/Source/NotEventDispatcher.php deleted file mode 100644 index dd853a15..00000000 --- a/tests/Rules/Symfony/SingleArgEventDispatchRule/Source/NotEventDispatcher.php +++ /dev/null @@ -1,11 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - $expectedErrorMessage = sprintf(SingleRequiredMethodRule::ERROR_MESSAGE, 2); - - yield [__DIR__ . '/Fixture/MultipleRequiredMethods.php', [[$expectedErrorMessage, 5]]]; - yield [__DIR__ . '/Fixture/MultipleRequiredAttributeMethods.php', [[$expectedErrorMessage, 7]]]; - - yield [__DIR__ . '/Fixture/SkipSingleRequiredMethod.php', []]; - } - - protected function getRule(): Rule - { - return new SingleRequiredMethodRule(); - } -} diff --git a/tests/Rules/UppercaseConstantRule/Fixture/ConstantLower.php b/tests/Rules/UppercaseConstantRule/Fixture/ConstantLower.php deleted file mode 100644 index e0942c48..00000000 --- a/tests/Rules/UppercaseConstantRule/Fixture/ConstantLower.php +++ /dev/null @@ -1,10 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - $errorMessage = sprintf(UppercaseConstantRule::ERROR_MESSAGE, 'SMall'); - yield [__DIR__ . '/Fixture/ConstantLower.php', [[$errorMessage, 9]]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(UppercaseConstantRule::class); - } -} diff --git a/tests/Rules/UppercaseConstantRule/config/configured_rule.neon b/tests/Rules/UppercaseConstantRule/config/configured_rule.neon deleted file mode 100644 index 510e5da4..00000000 --- a/tests/Rules/UppercaseConstantRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\UppercaseConstantRule diff --git a/tests/SomeClass.php.inc b/tests/SomeClass.php.inc deleted file mode 100644 index 17ce8504..00000000 --- a/tests/SomeClass.php.inc +++ /dev/null @@ -1,13 +0,0 @@ -name; - } -} diff --git a/tests/autoload.php b/tests/autoload.php deleted file mode 100644 index ec79412d..00000000 --- a/tests/autoload.php +++ /dev/null @@ -1,7 +0,0 @@ -