Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/downgraded_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
-
uses: "shivammathur/setup-php@v2"
with:
php-version: 8.2
php-version: 8.3
coverage: none

# invoke patches
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
5 changes: 0 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ parameters:

- '#Parameter \#1 \$objectOrClass of class ReflectionClass constructor expects class-string<T of object>\|T of object, string given#'

# command status enum
-
identifier: return.unusedType
path: src/Command/

# testing on purpose
-
identifier: method.alreadyNarrowedType
Expand Down
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
codeQuality: true,
deadCode: true,
typeDeclarations: true,
typeDeclarationDocblocks: true,
privatization: true,
earlyReturn: true,
codingStyle: true,
Expand Down
5 changes: 1 addition & 4 deletions src/Command/CheckCommentedCodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions src/Command/FinalizeClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/GenerateSymfonyConfigBuildersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/Comments/CommentedCodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
3 changes: 1 addition & 2 deletions src/EntityClassResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
final readonly class EntityClassResolver
{
/**
* @var string
* @see https://regex101.com/r/YFbH1x/1
*/
private const YAML_ENTITY_CLASS_NAME_REGEX = '#^(?<class_name>[\w+\\\\]+)\:\n#m';
private const string YAML_ENTITY_CLASS_NAME_REGEX = '#^(?<class_name>[\w+\\\\]+)\:\n#m';

public function __construct(
private CachedPhpParser $cachedPhpParser
Expand Down
10 changes: 2 additions & 8 deletions src/Enum/StaticAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
7 changes: 3 additions & 4 deletions src/Enum/SymfonyClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
54 changes: 15 additions & 39 deletions src/Enum/SymfonyExtensionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
3 changes: 1 addition & 2 deletions src/Git/ConflictResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 1 addition & 5 deletions src/Testing/Command/DetectUnitTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Testing/MockWire.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 5 additions & 7 deletions src/Testing/UnitTestFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace Rector\SwissKnife\Testing;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

final class UnitTestFilter
{
/**
* @var string[]|class-string<KernelTestCase>[]
*/
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',
];

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/EntityClassResolver/EntityClassResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +15,7 @@ final class EntityClassResolverTest extends AbstractTestCase
{
private EntityClassResolver $entityClassResolver;

#[Override]
protected function setUp(): void
{
parent::setUp();
Expand Down
3 changes: 3 additions & 0 deletions tests/Git/ConflictResolver/ConflictResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function test(string $filePath, int $expectedConflictCount): void
$this->assertSame($expectedConflictCount, $unresolvedConflictCount);
}

/**
* @return Iterator<(array<int, int>|array<int, string>)>
*/
public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/another_file.txt', 1];
Expand Down
2 changes: 2 additions & 0 deletions tests/NeedsFinalizeAnalyzer/NeedsFinalizeAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,6 +14,7 @@ final class NeedsFinalizeAnalyzerTest extends AbstractTestCase
{
private NeedsFinalizeAnalyzer $needsFinalizeAnalyzer;

#[Override]
protected function setUp(): void
{
parent::setUp();
Expand Down
2 changes: 2 additions & 0 deletions tests/ParentClassResolver/ParentClassResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,7 @@ final class ParentClassResolverTest extends AbstractTestCase
{
private ParentClassResolver $parentClassResolver;

#[Override]
protected function setUp(): void
{
parent::setUp();
Expand Down
Loading