diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 8a1551024..e427c16a2 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -52,7 +52,7 @@ jobs: # see https://github.com/shivammathur/setup-php - uses: shivammathur/setup-php@v2 with: - php-version: 8.2 + php-version: 8.3 coverage: none # composer install cache - https://github.com/ramsey/composer-install diff --git a/.github/workflows/downgraded_release.yaml b/.github/workflows/downgraded_release.yaml index 0083a7690..bb502355a 100644 --- a/.github/workflows/downgraded_release.yaml +++ b/.github/workflows/downgraded_release.yaml @@ -19,7 +19,7 @@ jobs: - uses: "shivammathur/setup-php@v2" with: - php-version: 8.2 + php-version: 8.3 coverage: none # invoke patches diff --git a/composer.json b/composer.json index 39e097b55..95767d3a1 100644 --- a/composer.json +++ b/composer.json @@ -6,8 +6,8 @@ "bin/swiss-knife" ], "require": { - "php": ">=8.2", - "illuminate/container": "^12.19", + "php": ">=8.3", + "illuminate/container": "12.38.*", "nette/robot-loader": "^4.0", "nette/utils": "^4.0", "nikic/php-parser": "^5.5", @@ -17,12 +17,12 @@ "webmozart/assert": "^1.11" }, "require-dev": { - "phpecs/phpecs": "^2.1", + "symplify/easy-coding-standard": "^13.0", "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^2.1", - "phpunit/phpunit": "^11.5", - "rector/jack": "^0.2.3", - "rector/rector": "^2.1", + "phpunit/phpunit": "^12.3", + "rector/jack": "^0.5.1", + "rector/rector": "^2.3", "shipmonk/composer-dependency-analyser": "^1.8", "symfony/config": "^6.4", "symfony/dependency-injection": "^6.4", diff --git a/phpstan.neon b/phpstan.neon index 95241dcd9..e3e6eb43f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -18,11 +18,6 @@ parameters: - '#Parameter \#1 \$objectOrClass of class ReflectionClass constructor expects class-string\|T of object, string given#' - # command status enum - - - identifier: return.unusedType - path: src/Command/ - # testing on purpose - identifier: method.alreadyNarrowedType diff --git a/rector.php b/rector.php index f4ed81953..ec6fe6492 100644 --- a/rector.php +++ b/rector.php @@ -11,6 +11,7 @@ codeQuality: true, deadCode: true, typeDeclarations: true, + typeDeclarationDocblocks: true, privatization: true, earlyReturn: true, codingStyle: true, diff --git a/src/Command/CheckCommentedCodeCommand.php b/src/Command/CheckCommentedCodeCommand.php index ea59988db..b78c56790 100644 --- a/src/Command/CheckCommentedCodeCommand.php +++ b/src/Command/CheckCommentedCodeCommand.php @@ -15,10 +15,7 @@ final class CheckCommentedCodeCommand extends Command { - /** - * @var int - */ - private const DEFAULT_LINE_LIMIT = 5; + private const int DEFAULT_LINE_LIMIT = 5; public function __construct( private readonly CommentedCodeAnalyzer $commentedCodeAnalyzer, diff --git a/src/Command/FinalizeClassesCommand.php b/src/Command/FinalizeClassesCommand.php index bf01b7e05..858f17ec4 100644 --- a/src/Command/FinalizeClassesCommand.php +++ b/src/Command/FinalizeClassesCommand.php @@ -25,7 +25,7 @@ final class FinalizeClassesCommand extends Command /** * @see https://regex101.com/r/Q5Nfbo/1 */ - private const NEWLINE_CLASS_START_REGEX = '#^(readonly )?class\s#m'; + private const string NEWLINE_CLASS_START_REGEX = '#^(readonly )?class\s#m'; public function __construct( private readonly SymfonyStyle $symfonyStyle, @@ -168,11 +168,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return self::FAILURE; } - $this->symfonyStyle->success(sprintf( - '%d %s finalized', - $countFinalizedClasses, - $pluralClassText, - )); + $this->symfonyStyle->success(sprintf('%d %s finalized', $countFinalizedClasses, $pluralClassText)); return self::SUCCESS; } diff --git a/src/Command/GenerateSymfonyConfigBuildersCommand.php b/src/Command/GenerateSymfonyConfigBuildersCommand.php index c1d2b0547..4e6ddd8c0 100644 --- a/src/Command/GenerateSymfonyConfigBuildersCommand.php +++ b/src/Command/GenerateSymfonyConfigBuildersCommand.php @@ -23,7 +23,7 @@ final class GenerateSymfonyConfigBuildersCommand extends Command /** * @var string[] */ - private const EXTENSION_CLASSES = [ + private const array EXTENSION_CLASSES = [ SymfonyExtensionClass::MONOLOG, SymfonyExtensionClass::SECURITY, SymfonyExtensionClass::TWIG, diff --git a/src/Comments/CommentedCodeAnalyzer.php b/src/Comments/CommentedCodeAnalyzer.php index ed3ddd013..b2596d135 100644 --- a/src/Comments/CommentedCodeAnalyzer.php +++ b/src/Comments/CommentedCodeAnalyzer.php @@ -13,11 +13,10 @@ final class CommentedCodeAnalyzer { /** - * @var string * @see https://regex101.com/r/5OlGjG/1 * @see https://3v4l.org/Y8pSD */ - private const NEWLINE_REGEX = '#\r?\n#'; + private const string NEWLINE_REGEX = '#\r?\n#'; /** * @return int[] diff --git a/src/EntityClassResolver.php b/src/EntityClassResolver.php index fde9ce189..042067a08 100644 --- a/src/EntityClassResolver.php +++ b/src/EntityClassResolver.php @@ -20,10 +20,9 @@ final readonly class EntityClassResolver { /** - * @var string * @see https://regex101.com/r/YFbH1x/1 */ - private const YAML_ENTITY_CLASS_NAME_REGEX = '#^(?[\w+\\\\]+)\:\n#m'; + private const string YAML_ENTITY_CLASS_NAME_REGEX = '#^(?[\w+\\\\]+)\:\n#m'; public function __construct( private CachedPhpParser $cachedPhpParser diff --git a/src/Enum/StaticAccessor.php b/src/Enum/StaticAccessor.php index 5ee622f1f..a16623dd2 100644 --- a/src/Enum/StaticAccessor.php +++ b/src/Enum/StaticAccessor.php @@ -6,13 +6,7 @@ final class StaticAccessor { - /** - * @var string - */ - public const STATIC = 'static'; + public const string STATIC = 'static'; - /** - * @var string - */ - public const SELF = 'self'; + public const string SELF = 'self'; } diff --git a/src/Enum/SymfonyClass.php b/src/Enum/SymfonyClass.php index 38601c608..e01828b9c 100644 --- a/src/Enum/SymfonyClass.php +++ b/src/Enum/SymfonyClass.php @@ -4,10 +4,9 @@ namespace Rector\SwissKnife\Enum; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; + final class SymfonyClass { - /** - * @var string - */ - public const CONTAINER_CONFIGURATOR_CLASS = 'Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator'; + public const string CONTAINER_CONFIGURATOR_CLASS = ContainerConfigurator::class; } diff --git a/src/Enum/SymfonyExtensionClass.php b/src/Enum/SymfonyExtensionClass.php index 9478758cd..31bb61547 100644 --- a/src/Enum/SymfonyExtensionClass.php +++ b/src/Enum/SymfonyExtensionClass.php @@ -6,43 +6,19 @@ final class SymfonyExtensionClass { - /** - * @var string - */ - public const SENTRY = 'Sentry\SentryBundle\DependencyInjection\SentryExtension'; - - /** - * @var string - */ - public const DOCTRINE_MIGRATIONS = 'Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension'; - - /** - * @var string - */ - public const FRAMEWORK = 'Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension'; - - /** - * @var string - */ - public const MONOLOG = 'Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension'; - - /** - * @var string - */ - public const SECURITY = 'Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension'; - - /** - * @var string - */ - public const TWIG = 'Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension'; - - /** - * @var string - */ - public const DOCTRINE = 'Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension'; - - /** - * @var string - */ - public const WEBPROFILER = 'Symfony\Bundle\WebProfilerBundle\DependencyInjection\WebProfilerExtension'; + public const string SENTRY = 'Sentry\SentryBundle\DependencyInjection\SentryExtension'; + + public const string DOCTRINE_MIGRATIONS = 'Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension'; + + public const string FRAMEWORK = 'Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension'; + + public const string MONOLOG = 'Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension'; + + public const string SECURITY = 'Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension'; + + public const string TWIG = 'Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension'; + + public const string DOCTRINE = 'Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension'; + + public const string WEBPROFILER = 'Symfony\Bundle\WebProfilerBundle\DependencyInjection\WebProfilerExtension'; } diff --git a/src/Git/ConflictResolver.php b/src/Git/ConflictResolver.php index 5a76534cd..ff0f40007 100644 --- a/src/Git/ConflictResolver.php +++ b/src/Git/ConflictResolver.php @@ -14,9 +14,8 @@ final class ConflictResolver { /** * @see https://regex101.com/r/L2CThC/1 - * @var string */ - private const CONFLICT_REGEX = '#^(<<<<<<<|>>>>>>>)#m'; + private const string CONFLICT_REGEX = '#^(<<<<<<<|>>>>>>>)#m'; /** * @api diff --git a/src/PhpParser/NodeVisitor/EntityClassNameCollectingNodeVisitor.php b/src/PhpParser/NodeVisitor/EntityClassNameCollectingNodeVisitor.php index a8eb848ef..a672151c1 100644 --- a/src/PhpParser/NodeVisitor/EntityClassNameCollectingNodeVisitor.php +++ b/src/PhpParser/NodeVisitor/EntityClassNameCollectingNodeVisitor.php @@ -16,12 +16,12 @@ final class EntityClassNameCollectingNodeVisitor extends NodeVisitorAbstract /** * @var string[] */ - private const ODM_SUFFIXES = ['Document', 'EmbeddedDocument']; + private const array ODM_SUFFIXES = ['Document', 'EmbeddedDocument']; /** * @var string[] */ - private const ORM_SUFFIXES = ['Entity', 'Embeddable']; + private const array ORM_SUFFIXES = ['Entity', 'Embeddable']; /** * @var string[] diff --git a/src/PhpParser/NodeVisitor/ExtractSymfonyExtensionCallNodeVisitor.php b/src/PhpParser/NodeVisitor/ExtractSymfonyExtensionCallNodeVisitor.php index 8eb0c6fb7..362e1d530 100644 --- a/src/PhpParser/NodeVisitor/ExtractSymfonyExtensionCallNodeVisitor.php +++ b/src/PhpParser/NodeVisitor/ExtractSymfonyExtensionCallNodeVisitor.php @@ -12,10 +12,7 @@ final class ExtractSymfonyExtensionCallNodeVisitor extends NodeVisitorAbstract { - /** - * @var string - */ - private const EXTENSION_METHOD_NAME = 'extension'; + private const string EXTENSION_METHOD_NAME = 'extension'; /** * @var MethodCall[] diff --git a/src/PhpParser/NodeVisitor/FindNonPrivateClassConstNodeVisitor.php b/src/PhpParser/NodeVisitor/FindNonPrivateClassConstNodeVisitor.php index 4ec9db569..4d617fd89 100644 --- a/src/PhpParser/NodeVisitor/FindNonPrivateClassConstNodeVisitor.php +++ b/src/PhpParser/NodeVisitor/FindNonPrivateClassConstNodeVisitor.php @@ -32,12 +32,12 @@ public function enterNode(Node $node): ?Node Assert::isInstanceOf($node->namespacedName, Name::class); $className = $node->namespacedName->toString(); - foreach ($node->getConstants() as $constant) { - foreach ($constant->consts as $constConst) { + foreach ($node->getConstants() as $classConst) { + foreach ($classConst->consts as $constConst) { $constantName = $constConst->name->toString(); // not interested in private constants - if ($constant->isPrivate()) { + if ($classConst->isPrivate()) { continue; } diff --git a/src/Testing/Command/DetectUnitTestsCommand.php b/src/Testing/Command/DetectUnitTestsCommand.php index 1f7cd0d6b..b29a3ba8f 100644 --- a/src/Testing/Command/DetectUnitTestsCommand.php +++ b/src/Testing/Command/DetectUnitTestsCommand.php @@ -16,10 +16,7 @@ final class DetectUnitTestsCommand extends Command { - /** - * @var string - */ - private const OUTPUT_FILENAME = 'phpunit-unit-files.xml'; + private const string OUTPUT_FILENAME = 'phpunit-unit-files.xml'; public function __construct( private readonly PHPUnitXmlPrinter $phpunitXmlPrinter, @@ -45,7 +42,6 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $sources = (array) $input->getArgument('sources'); - Assert::isArray($sources); Assert::allString($sources); $unitTestCasesClassesToFilePaths = $this->unitTestFilePathsFinder->findInDirectories($sources); diff --git a/src/Testing/MockWire.php b/src/Testing/MockWire.php index 657ab2d2d..2fba87a32 100644 --- a/src/Testing/MockWire.php +++ b/src/Testing/MockWire.php @@ -72,8 +72,8 @@ public static function create(string $class, array $constructorDependencies = [] $constructorMocks = []; - foreach ($constructorClassMethod->getParameters() as $parameterReflection) { - $constructorMocks[] = self::matchPassedMockOrCreate($constructorDependencies, $parameterReflection); + foreach ($constructorClassMethod->getParameters() as $reflectionParameter) { + $constructorMocks[] = self::matchPassedMockOrCreate($constructorDependencies, $reflectionParameter); } return new $class(...$constructorMocks); diff --git a/src/Testing/UnitTestFilter.php b/src/Testing/UnitTestFilter.php index 3927b2668..65b58ed7b 100644 --- a/src/Testing/UnitTestFilter.php +++ b/src/Testing/UnitTestFilter.php @@ -4,13 +4,15 @@ namespace Rector\SwissKnife\Testing; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; + final class UnitTestFilter { /** * @var string[]|class-string[] */ - private const NON_UNIT_TEST_CASE_CLASSES = [ - 'Symfony\Bundle\FrameworkBundle\Test\KernelTestCase', + private const array NON_UNIT_TEST_CASE_CLASSES = [ + KernelTestCase::class, 'Symfony\Component\Form\Test\TypeTestCase', ]; @@ -20,11 +22,7 @@ final class UnitTestFilter */ public function filter(array $testClassesToFilePaths): array { - return array_filter( - $testClassesToFilePaths, - fn (string $testClass): bool => $this->isUnitTest($testClass), - ARRAY_FILTER_USE_KEY - ); + return array_filter($testClassesToFilePaths, $this->isUnitTest(...), ARRAY_FILTER_USE_KEY); } private function isUnitTest(string $class): bool diff --git a/tests/EntityClassResolver/EntityClassResolverTest.php b/tests/EntityClassResolver/EntityClassResolverTest.php index e482b6bfb..c3b2afd24 100644 --- a/tests/EntityClassResolver/EntityClassResolverTest.php +++ b/tests/EntityClassResolver/EntityClassResolverTest.php @@ -4,6 +4,7 @@ namespace Rector\SwissKnife\Tests\EntityClassResolver; +use Override; use Rector\SwissKnife\EntityClassResolver; use Rector\SwissKnife\Tests\AbstractTestCase; use Rector\SwissKnife\Tests\EntityClassResolver\Fixture\Anything\SomeAttributeDocument; @@ -14,6 +15,7 @@ final class EntityClassResolverTest extends AbstractTestCase { private EntityClassResolver $entityClassResolver; + #[Override] protected function setUp(): void { parent::setUp(); diff --git a/tests/Git/ConflictResolver/ConflictResolverTest.php b/tests/Git/ConflictResolver/ConflictResolverTest.php index 88a0b6bac..6fadf5ad0 100644 --- a/tests/Git/ConflictResolver/ConflictResolverTest.php +++ b/tests/Git/ConflictResolver/ConflictResolverTest.php @@ -25,6 +25,9 @@ public function test(string $filePath, int $expectedConflictCount): void $this->assertSame($expectedConflictCount, $unresolvedConflictCount); } + /** + * @return Iterator<(array|array)> + */ public static function provideData(): Iterator { yield [__DIR__ . '/Fixture/another_file.txt', 1]; diff --git a/tests/NeedsFinalizeAnalyzer/NeedsFinalizeAnalyzerTest.php b/tests/NeedsFinalizeAnalyzer/NeedsFinalizeAnalyzerTest.php index 9b1a862f5..03d0f2798 100644 --- a/tests/NeedsFinalizeAnalyzer/NeedsFinalizeAnalyzerTest.php +++ b/tests/NeedsFinalizeAnalyzer/NeedsFinalizeAnalyzerTest.php @@ -4,6 +4,7 @@ namespace Rector\SwissKnife\Tests\NeedsFinalizeAnalyzer; +use Override; use PHPUnit\Framework\Attributes\DataProvider; use Rector\SwissKnife\Analyzer\NeedsFinalizeAnalyzer; use Rector\SwissKnife\PhpParser\CachedPhpParser; @@ -13,6 +14,7 @@ final class NeedsFinalizeAnalyzerTest extends AbstractTestCase { private NeedsFinalizeAnalyzer $needsFinalizeAnalyzer; + #[Override] protected function setUp(): void { parent::setUp(); diff --git a/tests/ParentClassResolver/ParentClassResolverTest.php b/tests/ParentClassResolver/ParentClassResolverTest.php index 541d7e285..91347734e 100644 --- a/tests/ParentClassResolver/ParentClassResolverTest.php +++ b/tests/ParentClassResolver/ParentClassResolverTest.php @@ -4,6 +4,7 @@ namespace Rector\SwissKnife\Tests\ParentClassResolver; +use Override; use Rector\SwissKnife\Finder\PhpFilesFinder; use Rector\SwissKnife\ParentClassResolver; use Rector\SwissKnife\Tests\AbstractTestCase; @@ -15,6 +16,7 @@ final class ParentClassResolverTest extends AbstractTestCase { private ParentClassResolver $parentClassResolver; + #[Override] protected function setUp(): void { parent::setUp(); diff --git a/tests/PhpParser/Finder/ClassConstFinder/ClassConstFinderTest.php b/tests/PhpParser/Finder/ClassConstFinder/ClassConstFinderTest.php index 048440999..0a17396df 100644 --- a/tests/PhpParser/Finder/ClassConstFinder/ClassConstFinderTest.php +++ b/tests/PhpParser/Finder/ClassConstFinder/ClassConstFinderTest.php @@ -5,6 +5,7 @@ namespace Rector\SwissKnife\Tests\PhpParser\Finder\ClassConstFinder; use Iterator; +use Override; use PHPUnit\Framework\Attributes\DataProvider; use Rector\SwissKnife\PhpParser\Finder\ClassConstFinder; use Rector\SwissKnife\Tests\AbstractTestCase; @@ -13,6 +14,7 @@ final class ClassConstFinderTest extends AbstractTestCase { private ClassConstFinder $classConstFinder; + #[Override] protected function setUp(): void { parent::setUp(); @@ -27,6 +29,9 @@ public function test(string $filePath, int $expectedClassConstantCount): void $this->assertCount($expectedClassConstantCount, $classConstants); } + /** + * @return Iterator<(array|array)> + */ public static function provideData(): Iterator { yield [__DIR__ . '/Fixture/SomeClassWithConstants.php', 1]; diff --git a/tests/PhpParser/Finder/ClassConstantFetchFinder/ClassConstantFetchFinderTest.php b/tests/PhpParser/Finder/ClassConstantFetchFinder/ClassConstantFetchFinderTest.php index 59746d465..c4ad59e63 100644 --- a/tests/PhpParser/Finder/ClassConstantFetchFinder/ClassConstantFetchFinderTest.php +++ b/tests/PhpParser/Finder/ClassConstantFetchFinder/ClassConstantFetchFinderTest.php @@ -4,6 +4,7 @@ namespace Rector\SwissKnife\Tests\PhpParser\Finder\ClassConstantFetchFinder; +use Override; use Rector\SwissKnife\Contract\ClassConstantFetchInterface; use Rector\SwissKnife\Finder\PhpFilesFinder; use Rector\SwissKnife\PhpParser\Finder\ClassConstantFetchFinder; @@ -18,6 +19,7 @@ final class ClassConstantFetchFinderTest extends AbstractTestCase { private ClassConstantFetchFinder $classConstantFetchFinder; + #[Override] protected function setUp(): void { parent::setUp(); diff --git a/tests/Testing/MockWire/MockWireTest.php b/tests/Testing/MockWire/MockWireTest.php index 5742b8114..9068d7f2d 100644 --- a/tests/Testing/MockWire/MockWireTest.php +++ b/tests/Testing/MockWire/MockWireTest.php @@ -12,10 +12,7 @@ final class MockWireTest extends TestCase { - /** - * @var string - */ - private const SECOND_VALUE = 'second'; + private const string SECOND_VALUE = 'second'; public function testOriginalService(): void { diff --git a/tests/Twig/TwigTemplateConstantExtractor/TwigTemplateConstantExtractorTest.php b/tests/Twig/TwigTemplateConstantExtractor/TwigTemplateConstantExtractorTest.php index b19fd6602..9c371f5b4 100644 --- a/tests/Twig/TwigTemplateConstantExtractor/TwigTemplateConstantExtractorTest.php +++ b/tests/Twig/TwigTemplateConstantExtractor/TwigTemplateConstantExtractorTest.php @@ -4,6 +4,7 @@ namespace Rector\SwissKnife\Tests\Twig\TwigTemplateConstantExtractor; +use Override; use Rector\SwissKnife\Contract\ClassConstantFetchInterface; use Rector\SwissKnife\Tests\AbstractTestCase; use Rector\SwissKnife\Tests\Twig\TwigTemplateConstantExtractor\Fixture\SomeTemplateUsedConstant; @@ -13,6 +14,7 @@ final class TwigTemplateConstantExtractorTest extends AbstractTestCase { private TwigTemplateConstantExtractor $twigTemplateConstantExtractor; + #[Override] protected function setUp(): void { parent::setUp(); diff --git a/tests/YAML/YamlConfigConstantExtractor/YamlConfigConstantExtractorTest.php b/tests/YAML/YamlConfigConstantExtractor/YamlConfigConstantExtractorTest.php index e12b46691..50e6b9649 100644 --- a/tests/YAML/YamlConfigConstantExtractor/YamlConfigConstantExtractorTest.php +++ b/tests/YAML/YamlConfigConstantExtractor/YamlConfigConstantExtractorTest.php @@ -4,6 +4,7 @@ namespace Rector\SwissKnife\Tests\YAML\YamlConfigConstantExtractor; +use Override; use Rector\SwissKnife\Tests\AbstractTestCase; use Rector\SwissKnife\Tests\YAML\YamlConfigConstantExtractor\Fixture\SomeClassWithConstant; use Rector\SwissKnife\YAML\YamlConfigConstantExtractor; @@ -12,6 +13,7 @@ final class YamlConfigConstantExtractorTest extends AbstractTestCase { private YamlConfigConstantExtractor $yamlConfigConstantExtractor; + #[Override] protected function setUp(): void { parent::setUp();