diff --git a/README.md b/README.md index f15166c2..c7adbcb9 100644 --- a/README.md +++ b/README.md @@ -108,38 +108,6 @@ class SomeClass
-## CheckClassNamespaceFollowPsr4Rule - -Class like namespace "%s" does not follow PSR-4 configuration in `composer.json` - -- class: [`Symplify\PHPStanRules\Rules\CheckClassNamespaceFollowPsr4Rule`](../src/Rules/CheckClassNamespaceFollowPsr4Rule.php) - -```php -// defined "Foo\Bar" namespace in composer.json > autoload > psr-4 -namespace Foo; - -class Baz -{ -} -``` - -:x: - -
- -```php -// defined "Foo\Bar" namespace in composer.json > autoload > psr-4 -namespace Foo\Bar; - -class Baz -{ -} -``` - -:+1: - -
- ## CheckRequiredInterfaceInContractNamespaceRule Interface must be located in "Contract" or "Contracts" namespace diff --git a/config/naming-rules.neon b/config/naming-rules.neon index aecaf6f4..6636a3f5 100644 --- a/config/naming-rules.neon +++ b/config/naming-rules.neon @@ -3,4 +3,3 @@ rules: - Symplify\PHPStanRules\Rules\NoReturnSetterMethodRule - Symplify\PHPStanRules\Rules\UppercaseConstantRule - Symplify\PHPStanRules\Rules\ClassNameRespectsParentSuffixRule - - Symplify\PHPStanRules\Rules\CheckClassNamespaceFollowPsr4Rule diff --git a/config/services/services.neon b/config/services/services.neon index 4e150c7d..2395cf42 100644 --- a/config/services/services.neon +++ b/config/services/services.neon @@ -5,11 +5,7 @@ services: - Symplify\PHPStanRules\Matcher\ArrayStringAndFnMatcher - Symplify\PHPStanRules\NodeFinder\TypeAwareNodeFinder - Symplify\PHPStanRules\PhpDoc\SeePhpDocTagNodesFinder - - Symplify\PHPStanRules\Composer\ClassNamespaceMatcher - - Symplify\PHPStanRules\Composer\ComposerAutoloadResolver - - Symplify\PHPStanRules\Composer\Psr4PathValidator - Symplify\PHPStanRules\Formatter\RequiredWithMessageFormatter - - Symplify\PHPStanRules\Location\DirectoryChecker - Symplify\PHPStanRules\Naming\ClassToSuffixResolver - Symplify\PHPStanRules\NodeAnalyzer\AttributeFinder - Symplify\PHPStanRules\NodeAnalyzer\EnumAnalyzer diff --git a/rector.php b/rector.php index 79bab7dd..d378204d 100644 --- a/rector.php +++ b/rector.php @@ -3,44 +3,19 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use Rector\PHPUnit\Set\PHPUnitSetList; -use Rector\Set\ValueObject\LevelSetList; -use Rector\Set\ValueObject\SetList; - -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->sets([ - PHPUnitSetList::PHPUNIT_100, - SetList::CODE_QUALITY, - SetList::DEAD_CODE, - LevelSetList::UP_TO_PHP_81, - SetList::CODING_STYLE, - SetList::TYPE_DECLARATION, - SetList::NAMING, - SetList::PRIVATIZATION, - SetList::EARLY_RETURN, - PHPUnitSetList::PHPUNIT_CODE_QUALITY, - ]); - - $rectorConfig->paths([ - __DIR__ . '/config', - __DIR__ . '/src', - __DIR__ . '/tests', - ]); - - $rectorConfig->importNames(); - - $rectorConfig->skip([ +use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; + +return RectorConfig::configure() + ->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/*', - - \Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class => [ + StringClassNameToClassConstantRector::class => [ __DIR__ . '/tests/Naming/ClassToSuffixResolverTest.php', __DIR__ . '/tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/PhpUpgradeImplementsMinPhpVersionInterfaceRuleTest.php', ], ]); - - $rectorConfig->ruleWithConfiguration(\Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class, [ - 'Symfony\Component\Console\*', - 'Rector\Contract\Rector\ConfigurableRectorInterface', - ]); -}; diff --git a/src/Composer/ClassNamespaceMatcher.php b/src/Composer/ClassNamespaceMatcher.php deleted file mode 100644 index d2279aac..00000000 --- a/src/Composer/ClassNamespaceMatcher.php +++ /dev/null @@ -1,65 +0,0 @@ - $autoloadPsr4Paths - * @return ClassNamespaceAndDirectory[] - */ - public function matchPossibleDirectoriesForClass( - string $namespaceBeforeClass, - array $autoloadPsr4Paths, - Scope $scope - ): array { - $namespaceToDirectories = []; - - foreach ($autoloadPsr4Paths as $namespace => $directory) { - $namespace = rtrim($namespace, '\\') . '\\'; - if ($namespaceBeforeClass === $namespace) { - return []; - } - - $directories = $this->standardizeToArray($directory); - foreach ($directories as $directory) { - if (! $this->directoryChecker->isInDirectoryNamed($scope, $directory)) { - continue; - } - - $namespaceToDirectories[] = new ClassNamespaceAndDirectory( - $namespace, - $directory, - $namespaceBeforeClass - ); - continue 2; - } - } - - return $namespaceToDirectories; - } - - /** - * @param string|string[] $items - * @return string[] - */ - private function standardizeToArray(string | array $items): array - { - if (! is_array($items)) { - return [$items]; - } - - return $items; - } -} diff --git a/src/Composer/ComposerAutoloadResolver.php b/src/Composer/ComposerAutoloadResolver.php deleted file mode 100644 index e9a254c6..00000000 --- a/src/Composer/ComposerAutoloadResolver.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ - public function getPsr4Autoload(): array - { - if (! file_exists(self::COMPOSER_JSON_FILE)) { - return []; - } - - $fileContent = FileSystem::read(self::COMPOSER_JSON_FILE); - $composerJsonContent = json_decode($fileContent, true, 512, JSON_THROW_ON_ERROR); - - $autoloadPsr4 = $composerJsonContent['autoload']['psr-4'] ?? []; - $autoloadDevPsr4 = $composerJsonContent['autoload-dev']['psr-4'] ?? []; - - return array_merge($autoloadPsr4, $autoloadDevPsr4); - } -} diff --git a/src/Composer/Psr4PathValidator.php b/src/Composer/Psr4PathValidator.php deleted file mode 100644 index bd5a8895..00000000 --- a/src/Composer/Psr4PathValidator.php +++ /dev/null @@ -1,47 +0,0 @@ -getSingleDirectory(), '/'); - $splitPaths = Strings::split($file, '#\/' . preg_quote($singleDirectory, '#') . '\/#'); - - if (count($splitPaths) === 1) { - return false; - } - - $directoryInNamespacedRoot = dirname((string) $splitPaths[1]); - $normalizedDirectoryInNamespacedRoot = $this->normalizePath($directoryInNamespacedRoot); - - $namespaceSuffixByDirectoryClass = ltrim($normalizedDirectoryInNamespacedRoot, '\\'); - - // @todo put into value object - $namespaceSuffixByNamespaceBeforeClass = rtrim( - substr( - $classNamespaceAndDirectory->getNamespaceBeforeClass(), - strlen($classNamespaceAndDirectory->getNamespace()) - ), - '\\' - ); - - return $namespaceSuffixByDirectoryClass === $namespaceSuffixByNamespaceBeforeClass; - } - - private function normalizePath(string $path): string - { - return str_replace('/', '\\', $path); - } -} diff --git a/src/Location/DirectoryChecker.php b/src/Location/DirectoryChecker.php deleted file mode 100644 index 9fda237b..00000000 --- a/src/Location/DirectoryChecker.php +++ /dev/null @@ -1,23 +0,0 @@ -normalizePath($directoryName); - $directoryName = rtrim($normalized, '\/'); - - return \str_contains($scope->getFile(), DIRECTORY_SEPARATOR . $directoryName . DIRECTORY_SEPARATOR); - } - - private function normalizePath(string $directoryName): string - { - return str_replace('/', DIRECTORY_SEPARATOR, $directoryName); - } -} diff --git a/src/NodeAnalyzer/EnumAnalyzer.php b/src/NodeAnalyzer/EnumAnalyzer.php index b5f8f94f..6d8d3adb 100644 --- a/src/NodeAnalyzer/EnumAnalyzer.php +++ b/src/NodeAnalyzer/EnumAnalyzer.php @@ -12,10 +12,10 @@ use PHPStan\Reflection\ClassReflection; use Symplify\PHPStanRules\PhpDoc\BarePhpDocParser; -final class EnumAnalyzer +final readonly class EnumAnalyzer { public function __construct( - private readonly BarePhpDocParser $barePhpDocParser + private BarePhpDocParser $barePhpDocParser ) { } diff --git a/src/NodeFinder/TypeAwareNodeFinder.php b/src/NodeFinder/TypeAwareNodeFinder.php index e00a884f..214007d9 100644 --- a/src/NodeFinder/TypeAwareNodeFinder.php +++ b/src/NodeFinder/TypeAwareNodeFinder.php @@ -10,9 +10,9 @@ /** * @todo remove after https://github.com/nikic/PHP-Parser/pull/869 is released */ -final class TypeAwareNodeFinder +final readonly class TypeAwareNodeFinder { - private readonly NodeFinder $nodeFinder; + private NodeFinder $nodeFinder; public function __construct() { diff --git a/src/ParentClassMethodNodeResolver.php b/src/ParentClassMethodNodeResolver.php index 16bbf4d4..8cc260c3 100644 --- a/src/ParentClassMethodNodeResolver.php +++ b/src/ParentClassMethodNodeResolver.php @@ -10,11 +10,11 @@ use PHPStan\Reflection\ReflectionProvider; use Symplify\PHPStanRules\Reflection\ReflectionParser; -final class ParentClassMethodNodeResolver +final readonly class ParentClassMethodNodeResolver { public function __construct( - private readonly ReflectionParser $reflectionParser, - private readonly ReflectionProvider $reflectionProvider + private ReflectionParser $reflectionParser, + private ReflectionProvider $reflectionProvider ) { } diff --git a/src/PhpDoc/BarePhpDocParser.php b/src/PhpDoc/BarePhpDocParser.php index 0617eecf..3caf70e3 100644 --- a/src/PhpDoc/BarePhpDocParser.php +++ b/src/PhpDoc/BarePhpDocParser.php @@ -12,11 +12,11 @@ use PHPStan\PhpDocParser\Parser\PhpDocParser; use PHPStan\PhpDocParser\Parser\TokenIterator; -final class BarePhpDocParser +final readonly class BarePhpDocParser { public function __construct( - private readonly PhpDocParser $phpDocParser, - private readonly Lexer $lexer + private PhpDocParser $phpDocParser, + private Lexer $lexer ) { } diff --git a/src/PhpDoc/PhpDocResolver.php b/src/PhpDoc/PhpDocResolver.php index fd892cb7..6975ff52 100644 --- a/src/PhpDoc/PhpDocResolver.php +++ b/src/PhpDoc/PhpDocResolver.php @@ -10,10 +10,10 @@ use PHPStan\Reflection\ClassReflection; use PHPStan\Type\FileTypeMapper; -final class PhpDocResolver +final readonly class PhpDocResolver { public function __construct( - private readonly FileTypeMapper $fileTypeMapper + private FileTypeMapper $fileTypeMapper ) { } diff --git a/src/Rules/CheckClassNamespaceFollowPsr4Rule.php b/src/Rules/CheckClassNamespaceFollowPsr4Rule.php deleted file mode 100644 index e1073358..00000000 --- a/src/Rules/CheckClassNamespaceFollowPsr4Rule.php +++ /dev/null @@ -1,99 +0,0 @@ - - * @see \Symplify\PHPStanRules\Tests\Rules\CheckClassNamespaceFollowPsr4Rule\CheckClassNamespaceFollowPsr4RuleTest - */ -final class CheckClassNamespaceFollowPsr4Rule implements Rule -{ - /** - * @var string - */ - public const ERROR_MESSAGE = 'Class like namespace "%s" does not follow PSR-4 configuration in composer.json'; - - /** - * @var array - */ - private array $autoloadPsr4Paths = []; - - public function __construct( - ComposerAutoloadResolver $composerAutoloadResolver, - private readonly Psr4PathValidator $psr4PathValidator, - private readonly ClassNamespaceMatcher $classNamespaceMatcher - ) { - $this->autoloadPsr4Paths = $composerAutoloadResolver->getPsr4Autoload(); - } - - /** - * @return class-string - */ - public function getNodeType(): string - { - return ClassLike::class; - } - - /** - * @param ClassLike $node - */ - public function processNode(Node $node, Scope $scope): array - { - if ($this->autoloadPsr4Paths === []) { - return []; - } - - $namespaceBeforeClass = $this->resolveNamespaceBeforeClass($node, $scope); - if ($namespaceBeforeClass === null) { - return []; - } - - $filePath = str_replace('\\', '/', $scope->getFile()); - - $possibleNamespacesToDirectories = $this->classNamespaceMatcher->matchPossibleDirectoriesForClass( - $namespaceBeforeClass, - $this->autoloadPsr4Paths, - $scope - ); - - if ($possibleNamespacesToDirectories === []) { - return []; - } - - foreach ($possibleNamespacesToDirectories as $possibleNamespaceToDirectory) { - if ($this->psr4PathValidator->isClassNamespaceCorrect($possibleNamespaceToDirectory, $filePath)) { - return []; - } - } - - if ($namespaceBeforeClass === '') { - return []; - } - - $namespacePart = substr($namespaceBeforeClass, 0, -1); - $errorMessage = sprintf(self::ERROR_MESSAGE, $namespacePart); - - return [RuleErrorBuilder::message($errorMessage)->identifier('check.classnamespacepsr4')->build()]; - } - - private function resolveNamespaceBeforeClass(ClassLike $classLike, Scope $scope): ?string - { - if (! $classLike->name instanceof Identifier) { - return null; - } - - return $scope->getNamespace() . '\\'; - } -} diff --git a/src/Rules/Enum/RequireUniqueEnumConstantRule.php b/src/Rules/Enum/RequireUniqueEnumConstantRule.php index 74c88892..e5432218 100644 --- a/src/Rules/Enum/RequireUniqueEnumConstantRule.php +++ b/src/Rules/Enum/RequireUniqueEnumConstantRule.php @@ -18,7 +18,7 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\Enum\RequireUniqueEnumConstantRule\RequireUniqueEnumConstantRuleTest */ -final class RequireUniqueEnumConstantRule implements Rule +final readonly class RequireUniqueEnumConstantRule implements Rule { /** * @var string @@ -26,7 +26,7 @@ final class RequireUniqueEnumConstantRule implements Rule public const ERROR_MESSAGE = 'Enum constants "%s" are duplicated. Make them unique instead'; public function __construct( - private readonly EnumAnalyzer $enumAnalyzer + private EnumAnalyzer $enumAnalyzer ) { } diff --git a/src/Rules/ForbiddenFuncCallRule.php b/src/Rules/ForbiddenFuncCallRule.php index 2ccc37a0..ca552b48 100644 --- a/src/Rules/ForbiddenFuncCallRule.php +++ b/src/Rules/ForbiddenFuncCallRule.php @@ -22,7 +22,7 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenFuncCallRule\ForbiddenFuncCallRuleTest */ -final class ForbiddenFuncCallRule implements Rule +final readonly class ForbiddenFuncCallRule implements Rule { /** * @var string @@ -33,9 +33,9 @@ final class ForbiddenFuncCallRule implements Rule * @param array $forbiddenFunctions */ public function __construct( - private readonly array $forbiddenFunctions, - private readonly ArrayStringAndFnMatcher $arrayStringAndFnMatcher, - private readonly RequiredWithMessageFormatter $requiredWithMessageFormatter, + private array $forbiddenFunctions, + private ArrayStringAndFnMatcher $arrayStringAndFnMatcher, + private RequiredWithMessageFormatter $requiredWithMessageFormatter, ) { } diff --git a/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php b/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php index 563abe24..1473b411 100644 --- a/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php +++ b/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php @@ -18,14 +18,14 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenMultipleClassLikeInOneFileRule\ForbiddenMultipleClassLikeInOneFileRuleTest */ -final class ForbiddenMultipleClassLikeInOneFileRule implements Rule +final readonly class ForbiddenMultipleClassLikeInOneFileRule implements Rule { /** * @var string */ public const ERROR_MESSAGE = 'Multiple class/interface/trait is not allowed in single file'; - private readonly NodeFinder $nodeFinder; + private NodeFinder $nodeFinder; public function __construct( ) { diff --git a/src/Rules/NoInlineStringRegexRule.php b/src/Rules/NoInlineStringRegexRule.php index 6d78fd9f..09ec5485 100644 --- a/src/Rules/NoInlineStringRegexRule.php +++ b/src/Rules/NoInlineStringRegexRule.php @@ -21,7 +21,7 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\NoInlineStringRegexRule\NoInlineStringRegexRuleTest */ -final class NoInlineStringRegexRule implements Rule +final readonly class NoInlineStringRegexRule implements Rule { /** * @var string @@ -29,8 +29,8 @@ final class NoInlineStringRegexRule implements Rule public const ERROR_MESSAGE = 'Use local named constant instead of inline string for regex to explain meaning by constant name'; public function __construct( - private readonly RegexFuncCallAnalyzer $regexFuncCallAnalyzer, - private readonly RegexStaticCallAnalyzer $regexStaticCallAnalyzer + private RegexFuncCallAnalyzer $regexFuncCallAnalyzer, + private RegexStaticCallAnalyzer $regexStaticCallAnalyzer ) { } diff --git a/src/Rules/NoReturnArrayVariableListRule.php b/src/Rules/NoReturnArrayVariableListRule.php index 9ea844b3..4f9ad3f2 100644 --- a/src/Rules/NoReturnArrayVariableListRule.php +++ b/src/Rules/NoReturnArrayVariableListRule.php @@ -23,7 +23,7 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\NoReturnArrayVariableListRule\NoReturnArrayVariableListRuleTest */ -final class NoReturnArrayVariableListRule implements Rule +final readonly class NoReturnArrayVariableListRule implements Rule { /** * @var string @@ -37,7 +37,7 @@ final class NoReturnArrayVariableListRule implements Rule private const TESTS_DIRECTORY_REGEX = '#\/Tests\/#i'; public function __construct( - private readonly ParentClassMethodNodeResolver $parentClassMethodNodeResolver, + private ParentClassMethodNodeResolver $parentClassMethodNodeResolver, ) { } diff --git a/src/Rules/NoReturnSetterMethodRule.php b/src/Rules/NoReturnSetterMethodRule.php index 6ab647dc..8defbbf3 100644 --- a/src/Rules/NoReturnSetterMethodRule.php +++ b/src/Rules/NoReturnSetterMethodRule.php @@ -21,7 +21,7 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\NoReturnSetterMethodRule\NoReturnSetterMethodRuleTest */ -final class NoReturnSetterMethodRule implements Rule +final readonly class NoReturnSetterMethodRule implements Rule { /** * @var string @@ -35,7 +35,7 @@ final class NoReturnSetterMethodRule implements Rule private const SETTER_START_REGEX = '#^set[A-Z]#'; public function __construct( - private readonly TypeAwareNodeFinder $typeAwareNodeFinder + private TypeAwareNodeFinder $typeAwareNodeFinder ) { } diff --git a/src/Rules/NoSingleInterfaceImplementerRule.php b/src/Rules/NoSingleInterfaceImplementerRule.php index f40ebe56..079ca670 100644 --- a/src/Rules/NoSingleInterfaceImplementerRule.php +++ b/src/Rules/NoSingleInterfaceImplementerRule.php @@ -19,7 +19,7 @@ /** * @see \Symplify\PHPStanRules\Tests\Rules\NoSingleInterfaceImplementerRule\NoSingleInterfaceImplementerRuleTest */ -final class NoSingleInterfaceImplementerRule implements Rule +final readonly class NoSingleInterfaceImplementerRule implements Rule { /** * @api used in test @@ -28,7 +28,7 @@ final class NoSingleInterfaceImplementerRule implements Rule public const ERROR_MESSAGE = 'Interface "%s" has only single implementer. Consider using the class directly as there is no point in using the interface.'; public function __construct( - private readonly ReflectionProvider $reflectionProvider + private ReflectionProvider $reflectionProvider ) { } diff --git a/src/Rules/PHPUnit/NoTestMocksRule.php b/src/Rules/PHPUnit/NoTestMocksRule.php index 77dfb89e..5542f57e 100644 --- a/src/Rules/PHPUnit/NoTestMocksRule.php +++ b/src/Rules/PHPUnit/NoTestMocksRule.php @@ -16,7 +16,7 @@ /** * @implements Rule */ -final class NoTestMocksRule implements Rule +final readonly class NoTestMocksRule implements Rule { /** * @api @@ -33,7 +33,7 @@ final class NoTestMocksRule implements Rule * @param string[] $allowedTypes */ public function __construct( - private readonly array $allowedTypes = [] + private array $allowedTypes = [] ) { } diff --git a/src/Rules/PreventParentMethodVisibilityOverrideRule.php b/src/Rules/PreventParentMethodVisibilityOverrideRule.php index c8ec0798..673e886a 100644 --- a/src/Rules/PreventParentMethodVisibilityOverrideRule.php +++ b/src/Rules/PreventParentMethodVisibilityOverrideRule.php @@ -18,7 +18,7 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\PreventParentMethodVisibilityOverrideRule\PreventParentMethodVisibilityOverrideRuleTest */ -final class PreventParentMethodVisibilityOverrideRule implements Rule +final readonly class PreventParentMethodVisibilityOverrideRule implements Rule { /** * @var string @@ -26,7 +26,7 @@ final class PreventParentMethodVisibilityOverrideRule implements Rule public const ERROR_MESSAGE = 'Change "%s()" method visibility to "%s" to respect parent method visibility.'; public function __construct( - private readonly ReflectionProvider $reflectionProvider + private ReflectionProvider $reflectionProvider ) { } diff --git a/src/Rules/RegexSuffixInRegexConstantRule.php b/src/Rules/RegexSuffixInRegexConstantRule.php index cdd4134e..37cf9d7e 100644 --- a/src/Rules/RegexSuffixInRegexConstantRule.php +++ b/src/Rules/RegexSuffixInRegexConstantRule.php @@ -22,7 +22,7 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\RegexSuffixInRegexConstantRule\RegexSuffixInRegexConstantRuleTest */ -final class RegexSuffixInRegexConstantRule implements Rule +final readonly class RegexSuffixInRegexConstantRule implements Rule { /** * @var string @@ -30,8 +30,8 @@ final class RegexSuffixInRegexConstantRule implements Rule public const ERROR_MESSAGE = 'Name your constant with "_REGEX" suffix, instead of "%s"'; public function __construct( - private readonly RegexFuncCallAnalyzer $regexFuncCallAnalyzer, - private readonly RegexStaticCallAnalyzer $regexStaticCallAnalyzer + private RegexFuncCallAnalyzer $regexFuncCallAnalyzer, + private RegexStaticCallAnalyzer $regexStaticCallAnalyzer ) { } diff --git a/src/Rules/SeeAnnotationToTestRule.php b/src/Rules/SeeAnnotationToTestRule.php index b47d2489..34ee037a 100644 --- a/src/Rules/SeeAnnotationToTestRule.php +++ b/src/Rules/SeeAnnotationToTestRule.php @@ -24,7 +24,7 @@ * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\SeeAnnotationToTestRule\SeeAnnotationToTestRuleTest */ -final class SeeAnnotationToTestRule implements Rule +final readonly class SeeAnnotationToTestRule implements Rule { /** * @var string @@ -35,9 +35,9 @@ final class SeeAnnotationToTestRule implements Rule * @param string[] $requiredSeeTypes */ public function __construct( - private readonly PhpDocResolver $phpDocResolver, - private readonly SeePhpDocTagNodesFinder $seePhpDocTagNodesFinder, - private readonly array $requiredSeeTypes + private PhpDocResolver $phpDocResolver, + private SeePhpDocTagNodesFinder $seePhpDocTagNodesFinder, + private array $requiredSeeTypes ) { } diff --git a/src/ValueObject/ClassNamespaceAndDirectory.php b/src/ValueObject/ClassNamespaceAndDirectory.php deleted file mode 100644 index bf129c84..00000000 --- a/src/ValueObject/ClassNamespaceAndDirectory.php +++ /dev/null @@ -1,30 +0,0 @@ -namespace; - } - - public function getSingleDirectory(): string - { - return $this->directory; - } - - public function getNamespaceBeforeClass(): string - { - return $this->namespaceBeforeClass; - } -} diff --git a/src/ValueObject/Configuration/RequiredWithMessage.php b/src/ValueObject/Configuration/RequiredWithMessage.php index d052ad3f..408f5b9e 100644 --- a/src/ValueObject/Configuration/RequiredWithMessage.php +++ b/src/ValueObject/Configuration/RequiredWithMessage.php @@ -4,11 +4,11 @@ namespace Symplify\PHPStanRules\ValueObject\Configuration; -final class RequiredWithMessage +final readonly class RequiredWithMessage { public function __construct( - private readonly string $required, - private readonly ?string $message + private string $required, + private ?string $message ) { } diff --git a/tests/Composer/Psr4PathValidatorTest.php b/tests/Composer/Psr4PathValidatorTest.php deleted file mode 100644 index 5c5b364d..00000000 --- a/tests/Composer/Psr4PathValidatorTest.php +++ /dev/null @@ -1,64 +0,0 @@ -psr4PathValidator = new Psr4PathValidator(); - } - - #[DataProvider('provideCorrectData')] - public function testCorrectCase(string $namespace, string $directory): void - { - $isClassNamespaceCorrect = $this->isNamespaceAndDirectoryCorrect($namespace, $directory); - - $this->assertTrue($isClassNamespaceCorrect); - } - - #[DataProvider('provideFailingData')] - public function testFailingCase(string $namespace, string $directory): void - { - $isClassNamespaceCorrect = $this->isNamespaceAndDirectoryCorrect($namespace, $directory); - - $this->assertFalse($isClassNamespaceCorrect); - } - - /** - * @return Iterator - */ - public static function provideCorrectData(): Iterator - { - yield ['Symplify\\PHPStanRules\\Tests\\', 'tests']; - yield ['Symplify\\PHPStanRules\\Tests\\', 'tests/']; - } - - public static function provideFailingData(): Iterator - { - yield ['Symplify\\PHPStanRules\\Tests\\', 'test/']; - yield ['Symplify\\PHPStanRules\\Tests\\', '/']; - yield ['PHPStanRules\\Tests', '/']; - } - - private function isNamespaceAndDirectoryCorrect(string $namespace, string $directory): bool - { - $classNamespaceAndDirectory = new ClassNamespaceAndDirectory( - $namespace, - $directory, - sprintf('%sComposer\\', $namespace) - ); - - return $this->psr4PathValidator->isClassNamespaceCorrect($classNamespaceAndDirectory, __FILE__); - } -} diff --git a/tests/Rules/CheckClassNamespaceFollowPsr4Rule/CheckClassNamespaceFollowPsr4RuleTest.php b/tests/Rules/CheckClassNamespaceFollowPsr4Rule/CheckClassNamespaceFollowPsr4RuleTest.php deleted file mode 100644 index f72ba522..00000000 --- a/tests/Rules/CheckClassNamespaceFollowPsr4Rule/CheckClassNamespaceFollowPsr4RuleTest.php +++ /dev/null @@ -1,58 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipAnonymousClass.php', []]; - yield [__DIR__ . '/Fixture/SkipValidNamespaceInterface.php', []]; - - yield [__DIR__ . '/Fixture/InvalidNamespaceClass.php', [ - [sprintf(CheckClassNamespaceFollowPsr4Rule::ERROR_MESSAGE, 'Foo\Bar'), 7], - ]]; - yield [__DIR__ . '/Fixture/InvalidNamespaceInterface.php', [ - [sprintf(CheckClassNamespaceFollowPsr4Rule::ERROR_MESSAGE, 'Foo\Bar'), 7], - ]]; - yield [__DIR__ . '/Fixture/InvalidNamespaceTrait.php', [ - [sprintf(CheckClassNamespaceFollowPsr4Rule::ERROR_MESSAGE, 'Foo\Bar'), 7], - ]]; - - $errorMessage = sprintf( - CheckClassNamespaceFollowPsr4Rule::ERROR_MESSAGE, - 'Symplify\PHPStanRules\Tests\Rules\CheckClassNamespaceFollowPsr4Rule' - ); - yield [__DIR__ . '/Fixture/MissingFixtureNamespaceClass.php', [[$errorMessage, 7]]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(CheckClassNamespaceFollowPsr4Rule::class); - } -} diff --git a/tests/Rules/CheckClassNamespaceFollowPsr4Rule/Fixture/InvalidNamespaceClass.php b/tests/Rules/CheckClassNamespaceFollowPsr4Rule/Fixture/InvalidNamespaceClass.php deleted file mode 100644 index 75cb9f95..00000000 --- a/tests/Rules/CheckClassNamespaceFollowPsr4Rule/Fixture/InvalidNamespaceClass.php +++ /dev/null @@ -1,10 +0,0 @@ -