Skip to content

Commit 67eb951

Browse files
committed
bump static rules
1 parent 89f7cf9 commit 67eb951

26 files changed

Lines changed: 179 additions & 181 deletions

composer.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@
55
"description": "Rector upgrades rules for Doctrine",
66
"require": {
77
"php": ">=8.2",
8-
"symfony/yaml": "^7.2"
8+
"symfony/yaml": "^7.4|8.0.*"
99
},
1010
"require-dev": {
11-
"doctrine/doctrine-bundle": "^2.14",
12-
"doctrine/orm": "^2.20",
13-
"phpecs/phpecs": "^2.1",
11+
"doctrine/doctrine-bundle": "^2.18|^3.0",
12+
"doctrine/orm": "^2.20|^3.0",
13+
"phpecs/phpecs": "^2.2",
1414
"phpstan/extension-installer": "^1.4",
1515
"phpstan/phpstan": "^2.1.14",
1616
"phpstan/phpstan-deprecation-rules": "^2.0",
1717
"phpstan/phpstan-webmozart-assert": "^2.0",
18-
"phpunit/phpunit": "^11.5",
18+
"phpunit/phpunit": "^11.5|^12.0",
19+
"rector/jack": "^0.4.0",
1920
"rector/rector-src": "dev-main",
2021
"rector/type-perfect": "^2.1",
2122
"symplify/phpstan-extensions": "^12.0",
22-
"symplify/phpstan-rules": "^14.6.9",
23-
"symplify/vendor-patches": "^11.3",
24-
"tomasvotruba/class-leak": "^2.0",
25-
"tracy/tracy": "^2.10"
23+
"symplify/phpstan-rules": "^14.9",
24+
"symplify/vendor-patches": "^11.5|^12.0",
25+
"tomasvotruba/class-leak": "^2.1",
26+
"tracy/tracy": "^2.11"
2627
},
2728
"autoload": {
2829
"psr-4": {

phpstan.neon

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# to be enabled later
21
includes:
32
- vendor/symplify/phpstan-rules/config/symplify-rules.neon
3+
- vendor/symplify/phpstan-rules/config/rector-rules.neon
44

55
parameters:
66
level: 8
@@ -78,3 +78,10 @@ parameters:
7878
-
7979
message: '#Function "property_exists\(\)" cannot be used/left in the code#'
8080
path: rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php
81+
82+
# stmts aware interface
83+
# - '#Access to an undefined property Rector\\Contract\\PhpParser\\Node\\StmtsAwareInterface::\$stmts#'
84+
85+
-
86+
path: tests/debug_functions.php
87+
message: '#Function "function_exists\(\)"#'

rector.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,23 @@
1010
->withPaths(
1111
[__DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/rules', __DIR__ . '/tests', __DIR__ . '/rules-tests']
1212
)
13-
->withSkip(['*/Source/*', '*/Fixture/*'])
13+
->withSkip([
14+
'*/Source/*',
15+
'*/Fixture/*',
16+
// class names on string to prevent from scope on downgrade
17+
StringClassNameToClassConstantRector::class => [__DIR__ . '/src/Enum/', __DIR__ . '/config/sets/'],
18+
])
1419
->withRootFiles()
1520
->withPhpSets()
1621
->withPreparedSets(
1722
deadCode: true,
1823
codeQuality: true,
1924
codingStyle: true,
2025
typeDeclarations: true,
26+
typeDeclarationDocblocks: true,
2127
privatization: true,
2228
naming: true,
29+
earlyReturn: true,
2330
rectorPreset: true
2431
)
2532
->withConfiguredRule(StringClassNameToClassConstantRector::class, [

rules-tests/Collection22/Rector/CriteriaOrderingConstantsDeprecations/CriteriaOrderingConstantDeprecationTest.php renamed to rules-tests/Collection22/Rector/CriteriaOrderingConstantsDeprecations/CriteriaOrderingConstantDeprecationRectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use PHPUnit\Framework\Attributes\DataProvider;
99
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
1010

11-
final class CriteriaOrderingConstantDeprecationTest extends AbstractRectorTestCase
11+
final class CriteriaOrderingConstantDeprecationRectorTest extends AbstractRectorTestCase
1212
{
1313
#[DataProvider('provideData')]
1414
public function test(string $filePath): void

rules/CodeQuality/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1818
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
1919
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
20+
use Rector\Doctrine\Enum\MappingClass;
2021
use Rector\Doctrine\NodeAnalyzer\ConstructorAssignPropertyAnalyzer;
2122
use Rector\Doctrine\NodeFactory\ValueAssignFactory;
2223
use Rector\Doctrine\NodeManipulator\ConstructorManipulator;
@@ -127,7 +128,7 @@ private function refactorProperty(Property $property, Class_ $class): void
127128
{
128129
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
129130

130-
$doctrineAnnotationTagValueNode = $phpDocInfo->getByAnnotationClass('Doctrine\ORM\Mapping\Column');
131+
$doctrineAnnotationTagValueNode = $phpDocInfo->getByAnnotationClass(MappingClass::COLUMN);
131132
if (! $doctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
132133
return;
133134
}

rules/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpParser\Node;
88
use PhpParser\Node\Stmt\Class_;
9+
use Rector\Doctrine\Enum\MappingClass;
910
use Rector\Rector\AbstractRector;
1011
use Rector\ValueObject\PhpVersionFeature;
1112
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
@@ -67,7 +68,7 @@ public function refactor(Node $node): ?Node
6768

6869
foreach ($node->attrGroups as $attrGroupKey => $attrGroup) {
6970
foreach ($attrGroup->attrs as $key => $attribute) {
70-
if (! $this->isName($attribute, 'Doctrine\ORM\Mapping\Table')) {
71+
if (! $this->isName($attribute, MappingClass::TABLE)) {
7172
continue;
7273
}
7374

rules/CodeQuality/Rector/Class_/TypeNullableEntityFromDocblockRector.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ public function refactor(Node $node): ?Class_
141141
}
142142

143143
$propertyType = $this->columnPropertyTypeResolver->resolve($property, true);
144-
if (! $propertyType instanceof Type || $propertyType instanceof MixedType) {
144+
if (! $propertyType instanceof Type) {
145+
continue;
146+
}
147+
148+
if ($propertyType instanceof MixedType) {
145149
continue;
146150
}
147151

rules/Collection22/Rector/CriteriaOrderingConstantsDeprecationRector.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@
1515
use PhpParser\Node\Name;
1616
use PhpParser\Node\Scalar\String_;
1717
use PHPStan\Type\ObjectType;
18+
use Rector\Doctrine\Enum\DoctrineClass;
1819
use Rector\Rector\AbstractRector;
1920
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2021
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2122

2223
/**
23-
* @see
24+
* @see \Rector\Doctrine\Tests\Collection22\Rector\CriteriaOrderingConstantsDeprecations\CriteriaOrderingConstantDeprecationRectorTest
2425
*/
2526
final class CriteriaOrderingConstantsDeprecationRector extends AbstractRector
2627
{
2728
private readonly ObjectType $criteriaObjectType;
2829

2930
public function __construct()
3031
{
31-
$this->criteriaObjectType = new ObjectType('Doctrine\Common\Collections\Criteria');
32+
$this->criteriaObjectType = new ObjectType(DoctrineClass::COLLECTIONS_CRITERIA);
3233
}
3334

3435
public function getRuleDefinition(): RuleDefinition
@@ -92,11 +93,7 @@ public function refactor(Node $node): ?Node
9293

9394
private function refactorClassConstFetch(ClassConstFetch $classConstFetch): ?Node
9495
{
95-
if (! $classConstFetch->name instanceof Identifier) {
96-
return null;
97-
}
98-
99-
if (! in_array($classConstFetch->name->name, ['ASC', 'DESC'])) {
96+
if (! $this->isNames($classConstFetch->name, ['ASC', 'DESC'])) {
10097
return null;
10198
}
10299

@@ -110,7 +107,10 @@ private function refactorClassConstFetch(ClassConstFetch $classConstFetch): ?Nod
110107
return null;
111108
}
112109

113-
return match ($classConstFetch->name->name) {
110+
/** @var "ASC"|"DESC" $constantName */
111+
$constantName = $this->getName($classConstFetch->name);
112+
113+
return match ($constantName) {
114114
'ASC' => new String_('ASC'),
115115
'DESC' => new String_('DESC'),
116116
};
@@ -195,7 +195,7 @@ private function refactorMethodCall(MethodCall $methodCall): ?Node
195195
private function buildArrayItem(string $direction, Expr|null $key): ArrayItem
196196
{
197197
$classConstFetch = $this->nodeFactory->createClassConstFetch(
198-
'Doctrine\Common\Collections\Order',
198+
DoctrineClass::ORDER,
199199
match ($direction) {
200200
'ASC' => 'Ascending',
201201
'DESC' => 'Descending',

rules/Dbal211/Rector/MethodCall/ExtractArrayArgOnQueryBuilderSelectRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpParser\Node\Expr\Array_;
1111
use PhpParser\Node\Expr\MethodCall;
1212
use PHPStan\Type\ObjectType;
13+
use Rector\Doctrine\Enum\DoctrineClass;
1314
use Rector\Rector\AbstractRector;
1415
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1516
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -65,7 +66,7 @@ public function refactor(Node $node): ?MethodCall
6566
return null;
6667
}
6768

68-
if (! $varType->isInstanceOf('Doctrine\DBAL\Query\QueryBuilder')->yes()) {
69+
if (! $varType->isInstanceOf(DoctrineClass::DBAL_QUERY_BUILDER)->yes()) {
6970
return null;
7071
}
7172

rules/Dbal211/Rector/MethodCall/ReplaceFetchAllMethodCallRector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpParser\Node\Expr\MethodCall;
1111
use PhpParser\Node\Identifier;
1212
use PHPStan\Type\ObjectType;
13+
use Rector\Doctrine\Enum\DoctrineClass;
1314
use Rector\Rector\AbstractRector;
1415
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1516
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -70,11 +71,11 @@ public function getNodeTypes(): array
7071
*/
7172
public function refactor(Node $node): ?Node
7273
{
73-
if ($this->isObjectType($node->var, new ObjectType('Doctrine\DBAL\Connection'))) {
74+
if ($this->isObjectType($node->var, new ObjectType(DoctrineClass::CONNECTION))) {
7475
return $this->refactorConnection($node);
7576
}
7677

77-
if ($this->isObjectType($node->var, new ObjectType('Doctrine\DBAL\Driver\ResultStatement'))) {
78+
if ($this->isObjectType($node->var, new ObjectType(DoctrineClass::RESULT_STATEMENT))) {
7879
return $this->refactorResultStatement($node);
7980
}
8081

0 commit comments

Comments
 (0)