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
18 changes: 16 additions & 2 deletions .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,31 @@ jobs:
name: 'Active Classes'
run: vendor/bin/class-leak check config src rules --ansi --skip-suffix "Rector" --skip-type "\Rector\Set\Contract\SetProviderInterface"

-
name: "Finalize Classes"
run: vendor/bin/swiss-knife finalize config src tests rules rules-tests --ansi

-
name: 'Composer Validate'
run: composer validate

-
name: 'PHPStan'
run: vendor/bin/phpstan

name: ${{ matrix.actions.name }}

runs-on: ubuntu-latest
timeout-minutes: 10

timeout-minutes: 5

steps:
- uses: actions/checkout@v4

-
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
coverage: none

- uses: "ramsey/composer-install@v2"
Expand Down
19 changes: 0 additions & 19 deletions .github/workflows/code_analysis_reusable.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
-
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
coverage: none

- uses: "ramsey/composer-install@v2"
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
"license": "MIT",
"description": "Rector upgrades rules for Symfony Framework",
"require": {
"php": ">=8.2",
"php": ">=8.3",
"ext-xml": "*"
},
"require-dev": {
"phpecs/phpecs": "^2.2",
"symplify/easy-coding-standard": "^13.0.4",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1.32",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-webmozart-assert": "^2.0",
"phpunit/phpunit": "^11.5",
"rector/jack": "^0.4",
"rector/jack": "^0.5",
"rector/rector-src": "dev-main",
"rector/swiss-knife": "^2.3",
"rector/type-perfect": "^2.1",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
Expand All @@ -30,7 +31,7 @@
"symplify/vendor-patches": "^11.5",
"tomasvotruba/class-leak": "^2.1",
"tomasvotruba/type-coverage": "^2.1",
"tomasvotruba/unused-public": "^2.1",
"tomasvotruba/unused-public": "^2.2",
"tracy/tracy": "^2.11"
},
"autoload": {
Expand Down
24 changes: 15 additions & 9 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# @todo enable
#includes:
# - vendor/symplify/phpstan-rules/config/symplify-rules.neon
# - vendor/symplify/phpstan-rules/config/rector-rules.neon
includes:
- vendor/symplify/phpstan-rules/config/symplify-rules.neon
- vendor/symplify/phpstan-rules/config/rector-rules.neon

rules:
- Symplify\PHPStanRules\Rules\StringFileAbsolutePathExistsRule
Expand All @@ -14,7 +13,7 @@ parameters:
typeAliases:
StmtsAware: \PhpParser\Node\Stmt\Block | \PhpParser\Node\Expr\Closure | \PhpParser\Node\Stmt\Case_ | \PhpParser\Node\Stmt\Catch_ | \PhpParser\Node\Stmt\ClassMethod | \PhpParser\Node\Stmt\Do_ | \PhpParser\Node\Stmt\Else_ | \PhpParser\Node\Stmt\ElseIf_ | \PhpParser\Node\Stmt\Finally_ | \PhpParser\Node\Stmt\For_ | \PhpParser\Node\Stmt\Foreach_ | \PhpParser\Node\Stmt\Function_ | \PhpParser\Node\Stmt\If_ | \PhpParser\Node\Stmt\Namespace_ | \PhpParser\Node\Stmt\TryCatch | \PhpParser\Node\Stmt\While_ | \Rector\PhpParser\Node\FileNode

reportUnmatchedIgnoredErrors: false
# reportUnmatchedIgnoredErrors: false
treatPhpDocTypesAsCertain: false

paths:
Expand Down Expand Up @@ -50,7 +49,6 @@ parameters:

# false positive
- '#but class PhpParser\\Node\\Stmt\\Expression is not generic#'
- '#Access to an undefined property Rector\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#'

# more advanced usage, but not always working
# see https://github.com/rectorphp/rector-src/actions/runs/11798721617/job/32865546672?pr=6422#step:5:110
Expand All @@ -69,13 +67,21 @@ parameters:

- '#Parameter 1 should use "PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionMethod" type as the only type passed to this method#'

# local use php 8.3
- identifier: typeCoverage.constantTypeCoverage

# in tests
-
message: '#Fetching deprecated class constant SYMFONY_(.*?) of class Rector\\Symfony\\Set\\SymfonySetList#'
paths:
- tests
- config/sets/symfony/annotations-to-attributes.php

# using XML to load symfony config
-
path: src/ValueObjectFactory/ServiceMapFactory.php
identifier: rector.noInstanceOfStaticReflection

-
path: src/ValueObjectFactory/ServiceMapFactory.php
message: '#"@simplexml_load_string\(\$fileContents\)" is forbidden to use#'



2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
// marked as skipped
ReturnNeverTypeRector::class => ['*/tests/*'],
])
// @todo cleanup rest and move to enum classes ass single place for class names
->withConfiguredRule(StringClassNameToClassConstantRector::class, ['Symfony\*', 'Twig_*', 'Twig*'])
->withPhpSets()
->withPreparedSets(
deadCode: true,
codeQuality: true,
codingStyle: true,
typeDeclarations: true,
typeDeclarationDocblocks: true,
privatization: true,
naming: true,
rectorPreset: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Symfony\Tests\CodeQuality\Rector\ClassMethod\ResponseReturnTypeControllerActionRector\Source;

class CustomObject
final class CustomObject
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\Routing\Annotation\Route;

class IntermediateController extends AbstractController
final class IntermediateController extends AbstractController
{
#[Route('/some-action', name: 'some_action')]
public function someAction(LoggerInterface $logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\ControllerMethodInjectionToConstructorRector\Source;

#[\Attribute]
class SomeType
final class SomeType
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

use Symfony\Component\Security\Core\User\UserInterface;

class SomeUser implements UserInterface
final class SomeUser implements UserInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Symfony\Tests\Configs\Rector\Closure\ServiceArgsToServiceNamedArgRector\Source;

class AnotherClassWithoutConstructor
final class AnotherClassWithoutConstructor
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace Rector\Symfony\Tests\Configs\Rector\Closure\ServiceArgsToServiceNamedArgRector\Source;

class SomeChildClassWithConstructor extends SomeClassWithConstructor
final class SomeChildClassWithConstructor extends SomeClassWithConstructor
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Symfony\Tests\Configs\Rector\Closure\ServiceArgsToServiceNamedArgRector\Source;

class SomeClassWithConstructor
final class SomeClassWithConstructor
{
public function __construct($someCtorParameter, $anotherCtorParameter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Symfony\Tests\Configs\Rector\Closure\ServiceSettersToSettersAutodiscoveryRector\Source;

class FirstAutowiredClass
final class FirstAutowiredClass
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Symfony\Tests\Configs\Rector\Closure\ServiceSettersToSettersAutodiscoveryRector\Source;

class SecondAutowiredClass
final class SecondAutowiredClass
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Symfony\Component\Form\AbstractType;

class CustomType extends AbstractType
final class CustomType extends AbstractType
{
public function getBlockPrefix()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Symfony\Component\Form\FormTypeInterface;

class AnotherFormTypeClass implements FormTypeInterface
final class AnotherFormTypeClass implements FormTypeInterface
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

class ClassWithVarDumperTrait
final class ClassWithVarDumperTrait
{
use VarDumperTestTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Rector\Symfony\Tests\Symfony43\Rector\MethodCall\WebTestCaseAssertResponseCodeRector\Source;

class FixtureWebTestCase
final class FixtureWebTestCase
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Symfony\Tests\Symfony44\Rector\MethodCall\AuthorizationCheckerIsGrantedExtractorRector\Source;

class DifferentClass
final class DifferentClass
{
public function isGranted($args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace Rector\Symfony\Tests\Symfony62\Rector\Class_\MessageHandlerInterfaceToAttributeRector\Source;

class SmsNotification
final class SmsNotification
{
}
25 changes: 5 additions & 20 deletions rules/CodeQuality/Enum/ResponseClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,13 @@

final class ResponseClass
{
/**
* @var string
*/
public const REDIRECT = 'Symfony\Component\HttpFoundation\RedirectResponse';
public const string REDIRECT = 'Symfony\Component\HttpFoundation\RedirectResponse';

/**
* @var string
*/
public const BINARY_FILE = 'Symfony\Component\HttpFoundation\BinaryFileResponse';
public const string BINARY_FILE = 'Symfony\Component\HttpFoundation\BinaryFileResponse';

/**
* @var string
*/
public const JSON = 'Symfony\Component\HttpFoundation\JsonResponse';
public const string JSON = 'Symfony\Component\HttpFoundation\JsonResponse';

/**
* @var string
*/
public const STREAMED = 'Symfony\Component\HttpFoundation\StreamedResponse';
public const string STREAMED = 'Symfony\Component\HttpFoundation\StreamedResponse';

/**
* @var string
*/
public const BASIC = 'Symfony\Component\HttpFoundation\Response';
public const string BASIC = 'Symfony\Component\HttpFoundation\Response';
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Doctrine\NodeAnalyzer\AttrinationFinder;
use Rector\PhpParser\Enum\NodeGroup;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\Rector\AbstractRector;
use Rector\Symfony\Annotation\AnnotationAnalyzer;
Expand Down Expand Up @@ -198,7 +199,8 @@ private function refactorClassMethod(
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}

if (! property_exists($node, 'stmts')) {
// has stmts
if (! NodeGroup::isStmtAwareNode($node)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class ControllerMethodInjectionToConstructorRector extends AbstractRector
/**
* @var string[]
*/
private const COMMON_ENTITY_CONTAINS_SUBNAMESPACES = ["\\Entity", "\\Document", "\\Model"];
private const array COMMON_ENTITY_CONTAINS_SUBNAMESPACES = ["\\Entity", "\\Document", "\\Model"];

public function __construct(
private readonly ControllerAnalyzer $controllerAnalyzer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
final class EventListenerToEventSubscriberRector extends AbstractRector
{
/**
* @var string
* @changelog https://regex101.com/r/qiHZ4T/1
*/
private const LISTENER_MATCH_REGEX = '#^(.*?)(Listener)?$#';
private const string LISTENER_MATCH_REGEX = '#^(.*?)(Listener)?$#';

/**
* @var EventNameToClassAndConstant[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ final class InlineClassRoutePrefixRector extends AbstractRector
/**
* @var string[]
*/
private const FOS_REST_ANNOTATIONS = [
private const array FOS_REST_ANNOTATIONS = [
FosAnnotation::REST_POST,
FosAnnotation::REST_GET,
FosAnnotation::REST_ROUTE,
];

/**
* @var string
*/
private const PATH = 'path';
private const string PATH = 'path';

public function __construct(
private readonly PhpDocInfoFactory $phpDocInfoFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @see \Rector\Symfony\Tests\CodeQuality\Rector\Class_\SplitAndSecurityAttributeToIsGrantedRector\SplitAndSecurityAttributeToIsGrantedRectorTest
*/
final class SplitAndSecurityAttributeToIsGrantedRector extends AbstractRector
{
public function getRuleDefinition(): RuleDefinition
Expand Down
Loading