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:
-
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: 8.4
coverage: none

- uses: "ramsey/composer-install@v2"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rector.yaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
-
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: 8.4
coverage: none

- uses: "ramsey/composer-install@v2"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"description": "Rector upgrades rules for Symfony Framework",
"require": {
"php": ">=8.3",
"php": ">=8.4",
"ext-xml": "*"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
use Rector\Symfony\Symfony81\Rector\MethodCall\ConstraintValidatorValidateToValidateInContextRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
ConstraintValidatorValidateToValidateInContextRector::class,
]);
$rectorConfig->rules([ConstraintValidatorValidateToValidateInContextRector::class]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,7 @@ public function provideMinPhpVersion(): int

private function hasParameterBagInterfaceDependency(ClassMethod $classMethod): bool
{
foreach ($classMethod->getParams() as $param) {
if ($this->isParameterBagParam($param)) {
return true;
}
}

return false;
return array_any($classMethod->getParams(), fn (Param $param): bool => $this->isParameterBagParam($param));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ public function getNodeTypes(): array
return [New_::class];
}

/**
* @param New_ $node
*/
public function refactor(Node $node): ?Node
{
if (! $node instanceof New_) {
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}
Expand Down
12 changes: 5 additions & 7 deletions rules/Symfony80/Rector/Class_/RemoveEraseCredentialsRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Modifiers;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -107,13 +108,10 @@ public function refactor(Node $node): ?Class_

private function doesImplementUserInterface(Class_ $class): bool
{
foreach ($class->implements as $implementedInterface) {
if ($this->isName($implementedInterface, SymfonyClass::USER_INTERFACE)) {
return true;
}
}

return false;
return array_any(
$class->implements,
fn (Name $name): bool => $this->isName($name, SymfonyClass::USER_INTERFACE)
);
}

private function createSserializeClassMethod(mixed $classMethodStmts): ClassMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,78 +107,70 @@ public function refactor(Node $node): ?Node
return $this->refactorConstraintValidatorCall($node);
}

private function refactorConstraintValidatorTestCaseCall(MethodCall $node): ?Node
private function refactorConstraintValidatorTestCaseCall(MethodCall $methodCall): ?Node
{
if ($this->isName($node->name, 'validate') && \count($node->args) === 2) {
return $this->createThisValidateMethodCall($node->args[0], $node->args[1]);
if ($this->isName($methodCall->name, 'validate') && \count($methodCall->args) === 2) {
return $this->createThisValidateMethodCall($methodCall->args[0], $methodCall->args[1]);
}

if ($this->isName($node->name, 'validateInContext') && \count($node->args) === 3) {
return $this->createThisValidateMethodCall($node->args[0], $node->args[1]);
if ($this->isName($methodCall->name, 'validateInContext') && \count($methodCall->args) === 3) {
return $this->createThisValidateMethodCall($methodCall->args[0], $methodCall->args[1]);
}

return null;
}

private function refactorConstraintValidatorCall(MethodCall $node): ?Node
private function refactorConstraintValidatorCall(MethodCall $methodCall): ?Node
{
if (! $this->isName($node->name, 'validate')) {
if (! $this->isName($methodCall->name, 'validate')) {
return null;
}

if (\count($node->args) !== 2) {
if (\count($methodCall->args) !== 2) {
return null;
}

if (! $this->isInsideConstraintValidator($node)) {
if (! $this->isInsideConstraintValidator($methodCall)) {
return null;
}

$node->name = new Identifier('validateInContext');
$node->args[] = new Arg($this->nodeFactory->createPropertyFetch(new Variable('this'), 'context'));
$methodCall->name = new Identifier('validateInContext');
$methodCall->args[] = new Arg($this->nodeFactory->createPropertyFetch(new Variable('this'), 'context'));

return $node;
return $methodCall;
}

/**
* @param Arg $firstArg
* @param Arg $secondArg
*/
private function createThisValidateMethodCall(Arg $firstArg, Arg $secondArg): MethodCall
{
return new MethodCall(
new Variable('this'),
new Identifier('validate'),
[$firstArg, $secondArg],
);
return new MethodCall(new Variable('this'), new Identifier('validate'), [$firstArg, $secondArg]);
}

private function isThisValidatorPropertyFetch(Expr $node): bool
private function isThisValidatorPropertyFetch(Expr $expr): bool
{
if (! $node instanceof PropertyFetch) {
if (! $expr instanceof PropertyFetch) {
return false;
}

if (! $this->isName($node->name, 'validator')) {
if (! $this->isName($expr->name, 'validator')) {
return false;
}

return $node->var instanceof Variable && $this->isName($node->var, 'this');
return $expr->var instanceof Variable && $this->isName($expr->var, 'this');
}

private function isInsideConstraintValidatorTestCase(MethodCall $node): bool
private function isInsideConstraintValidatorTestCase(MethodCall $methodCall): bool
{
return $this->isInsideClassSubclassOf($node, ConstraintValidatorTestCase::class);
return $this->isInsideClassSubclassOf($methodCall, ConstraintValidatorTestCase::class);
}

private function isInsideConstraintValidator(MethodCall $node): bool
private function isInsideConstraintValidator(MethodCall $methodCall): bool
{
return $this->isInsideClassSubclassOf($node, ConstraintValidator::class);
return $this->isInsideClassSubclassOf($methodCall, ConstraintValidator::class);
}

private function isInsideClassSubclassOf(MethodCall $node, string $className): bool
private function isInsideClassSubclassOf(MethodCall $methodCall, string $className): bool
{
$scope = ScopeFetcher::fetch($node);
$scope = ScopeFetcher::fetch($methodCall);
$classReflection = $scope->getClassReflection();
if (! $classReflection instanceof ClassReflection) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if (! $node instanceof New_) {
return null;
}

if (! $this->isName($node->class, 'Symfony\Component\Security\Http\Authentication\AuthenticatorManager')) {
return null;
}
Expand Down
15 changes: 8 additions & 7 deletions src/Annotation/AnnotationAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Symfony\Annotation;

use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Doctrine\NodeAnalyzer\AttrinationFinder;
use Rector\Symfony\Enum\SymfonyAnnotation;

Expand All @@ -21,12 +22,12 @@ public function hasClassMethodWithTemplateAnnotation(Class_ $class): bool
return true;
}

foreach ($class->getMethods() as $classMethod) {
if ($this->attrinationFinder->hasByOne($classMethod, SymfonyAnnotation::TEMPLATE)) {
return true;
}
}

return false;
return array_any(
$class->getMethods(),
fn (ClassMethod $classMethod): bool => $this->attrinationFinder->hasByOne(
$classMethod,
SymfonyAnnotation::TEMPLATE
)
);
}
}
3 changes: 3 additions & 0 deletions src/Bridge/Symfony/ContainerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Symfony\Component\DependencyInjection\Container;
use Webmozart\Assert\Assert;

/**
* @see \Rector\Symfony\Tests\Bridge\Symfony\ContainerServiceProviderTest
*/
final class ContainerServiceProvider
{
private ?object $container = null;
Expand Down
12 changes: 5 additions & 7 deletions src/NodeAnalyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Symfony\NodeAnalyzer;

use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use Rector\NodeNameResolver\NodeNameResolver;

Expand All @@ -16,12 +17,9 @@ public function __construct(

public function hasImplements(Class_ $class, string $interfaceFQN): bool
{
foreach ($class->implements as $implement) {
if ($this->nodeNameResolver->isName($implement, $interfaceFQN)) {
return true;
}
}

return false;
return array_any(
$class->implements,
fn (Name $name): bool => $this->nodeNameResolver->isName($name, $interfaceFQN)
);
}
}
Loading
Loading