Skip to content

Commit 4b9bfe1

Browse files
committed
Updated Rector to commit 730c316ecce7603c42899ba0c8d087de8d67ce60
rectorphp/rector-src@730c316 Update code sample for SimplifyEmptyCheckOnEmptyArrayRector (#7897)
1 parent 7115ccf commit 4b9bfe1

7 files changed

Lines changed: 137 additions & 7 deletions

File tree

‎vendor/composer/autoload_classmap.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,7 @@
16811681
'Rector\\DowngradePhp81\\Rector\\StmtsAwareInterface\\DowngradeSetAccessibleReflectionPropertyRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/StmtsAwareInterface/DowngradeSetAccessibleReflectionPropertyRector.php',
16821682
'Rector\\DowngradePhp82\\NodeManipulator\\DowngradeReadonlyClassManipulator' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp82/NodeManipulator/DowngradeReadonlyClassManipulator.php',
16831683
'Rector\\DowngradePhp82\\Rector\\Class_\\DowngradeReadonlyClassRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp82/Rector/Class_/DowngradeReadonlyClassRector.php',
1684+
'Rector\\DowngradePhp82\\Rector\\Class_\\DowngradeUnionIntersectionRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp82/Rector/Class_/DowngradeUnionIntersectionRector.php',
16841685
'Rector\\DowngradePhp82\\Rector\\FuncCall\\DowngradeIteratorCountToArrayRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp82/Rector/FuncCall/DowngradeIteratorCountToArrayRector.php',
16851686
'Rector\\DowngradePhp82\\Rector\\FunctionLike\\DowngradeStandaloneNullTrueFalseReturnTypeRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp82/Rector/FunctionLike/DowngradeStandaloneNullTrueFalseReturnTypeRector.php',
16861687
'Rector\\DowngradePhp83\\Rector\\ClassConstFetch\\DowngradeDynamicClassConstFetchRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp83/Rector/ClassConstFetch/DowngradeDynamicClassConstFetchRector.php',

‎vendor/composer/autoload_static.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,7 @@ class ComposerStaticInit6826166f41bd7c9c1cfd80bf44288c10
19411941
'Rector\\DowngradePhp81\\Rector\\StmtsAwareInterface\\DowngradeSetAccessibleReflectionPropertyRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/StmtsAwareInterface/DowngradeSetAccessibleReflectionPropertyRector.php',
19421942
'Rector\\DowngradePhp82\\NodeManipulator\\DowngradeReadonlyClassManipulator' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp82/NodeManipulator/DowngradeReadonlyClassManipulator.php',
19431943
'Rector\\DowngradePhp82\\Rector\\Class_\\DowngradeReadonlyClassRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp82/Rector/Class_/DowngradeReadonlyClassRector.php',
1944+
'Rector\\DowngradePhp82\\Rector\\Class_\\DowngradeUnionIntersectionRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp82/Rector/Class_/DowngradeUnionIntersectionRector.php',
19441945
'Rector\\DowngradePhp82\\Rector\\FuncCall\\DowngradeIteratorCountToArrayRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp82/Rector/FuncCall/DowngradeIteratorCountToArrayRector.php',
19451946
'Rector\\DowngradePhp82\\Rector\\FunctionLike\\DowngradeStandaloneNullTrueFalseReturnTypeRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp82/Rector/FunctionLike/DowngradeStandaloneNullTrueFalseReturnTypeRector.php',
19461947
'Rector\\DowngradePhp83\\Rector\\ClassConstFetch\\DowngradeDynamicClassConstFetchRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp83/Rector/ClassConstFetch/DowngradeDynamicClassConstFetchRector.php',

‎vendor/composer/installed.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,12 +1759,12 @@
17591759
"source": {
17601760
"type": "git",
17611761
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
1762-
"reference": "b0da459893a4b68697879b6888d5ce858f0a5850"
1762+
"reference": "8c5e9e1c994be702b14814fcdf4290c4eeb0486f"
17631763
},
17641764
"dist": {
17651765
"type": "zip",
1766-
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/b0da459893a4b68697879b6888d5ce858f0a5850",
1767-
"reference": "b0da459893a4b68697879b6888d5ce858f0a5850",
1766+
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/8c5e9e1c994be702b14814fcdf4290c4eeb0486f",
1767+
"reference": "8c5e9e1c994be702b14814fcdf4290c4eeb0486f",
17681768
"shasum": ""
17691769
},
17701770
"require": {
@@ -1788,7 +1788,7 @@
17881788
"tomasvotruba\/unused-public": "^2.2",
17891789
"tracy\/tracy": "^2.11"
17901790
},
1791-
"time": "2026-02-14T06:40:16+00:00",
1791+
"time": "2026-02-17T10:24:09+00:00",
17921792
"default-branch": true,
17931793
"type": "rector-extension",
17941794
"extra": {

‎vendor/composer/installed.php‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎vendor/rector/extension-installer/src/GeneratedConfig.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
final class GeneratedConfig
1111
{
12-
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 46e4f77'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main b0da459'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main adce7d9'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main e9008b6'));
12+
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 46e4f77'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 8c5e9e1'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main adce7d9'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main e9008b6'));
1313
private function __construct()
1414
{
1515
}

‎vendor/rector/rector-downgrade-php/config/set/downgrade-php82.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
use Rector\Config\RectorConfig;
77
use Rector\ValueObject\PhpVersion;
88
use Rector\DowngradePhp82\Rector\Class_\DowngradeReadonlyClassRector;
9+
use Rector\DowngradePhp82\Rector\Class_\DowngradeUnionIntersectionRector;
910
use Rector\DowngradePhp82\Rector\FuncCall\DowngradeIteratorCountToArrayRector;
1011
use Rector\DowngradePhp82\Rector\FunctionLike\DowngradeStandaloneNullTrueFalseReturnTypeRector;
1112
return static function (RectorConfig $rectorConfig): void {
1213
$rectorConfig->phpVersion(PhpVersion::PHP_81);
13-
$rectorConfig->rules([DowngradeReadonlyClassRector::class, DowngradeStandaloneNullTrueFalseReturnTypeRector::class, DowngradeIteratorCountToArrayRector::class]);
14+
$rectorConfig->rules([DowngradeReadonlyClassRector::class, DowngradeStandaloneNullTrueFalseReturnTypeRector::class, DowngradeIteratorCountToArrayRector::class, DowngradeUnionIntersectionRector::class]);
1415
};
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\DowngradePhp82\Rector\Class_;
5+
6+
use PhpParser\Node;
7+
use PhpParser\Node\Expr\ArrowFunction;
8+
use PhpParser\Node\Expr\Closure;
9+
use PhpParser\Node\IntersectionType;
10+
use PhpParser\Node\Stmt\ClassLike;
11+
use PhpParser\Node\Stmt\ClassMethod;
12+
use PhpParser\Node\Stmt\Function_;
13+
use PhpParser\Node\UnionType;
14+
use Rector\NodeManipulator\PropertyDecorator;
15+
use Rector\PhpDocDecorator\PhpDocFromTypeDeclarationDecorator;
16+
use Rector\Rector\AbstractRector;
17+
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
18+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
19+
use RectorPrefix202602\Webmozart\Assert\Assert;
20+
/**
21+
* @changelog https://php.watch/versions/8.2/dnf-types
22+
*
23+
* @see \Rector\Tests\DowngradePhp82\Rector\Class_\DowngradeUnionIntersectionRector\DowngradeUnionIntersectionRectorTest
24+
*/
25+
final class DowngradeUnionIntersectionRector extends AbstractRector
26+
{
27+
/**
28+
* @readonly
29+
*/
30+
private PropertyDecorator $propertyDecorator;
31+
/**
32+
* @readonly
33+
*/
34+
private PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator;
35+
public function __construct(PropertyDecorator $propertyDecorator, PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
36+
{
37+
$this->propertyDecorator = $propertyDecorator;
38+
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
39+
}
40+
public function getRuleDefinition(): RuleDefinition
41+
{
42+
return new RuleDefinition('Remove the union type with intersection, use docblock based', [new CodeSample(<<<'CODE_SAMPLE'
43+
final class SomeClass
44+
{
45+
public (A&B)|C $foo;
46+
}
47+
CODE_SAMPLE
48+
, <<<'CODE_SAMPLE'
49+
final class SomeClass
50+
{
51+
/**
52+
* @var (A&B)|C
53+
*/
54+
public $foo;
55+
}
56+
CODE_SAMPLE
57+
)]);
58+
}
59+
/**
60+
* @return array<class-string<Node>>
61+
*/
62+
public function getNodeTypes(): array
63+
{
64+
return [ClassLike::class, ClassMethod::class, Function_::class, Closure::class, ArrowFunction::class];
65+
}
66+
/**
67+
* @param ClassLike|ClassMethod|Function_|Closure|ArrowFunction $node
68+
*/
69+
public function refactor(Node $node): ?Node
70+
{
71+
if (!$node instanceof ClassLike) {
72+
return $this->processFunctionLike($node);
73+
}
74+
return $this->processClassLike($node);
75+
}
76+
/**
77+
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $functionLike
78+
* @return null|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction
79+
*/
80+
private function processFunctionLike($functionLike)
81+
{
82+
$paramDecorated = \false;
83+
foreach ($functionLike->getParams() as $param) {
84+
if (!$this->isUnionIntersection($param->type)) {
85+
continue;
86+
}
87+
Assert::isInstanceOf($param->type, UnionType::class);
88+
$this->phpDocFromTypeDeclarationDecorator->decorateParam($param, $functionLike, [\PHPStan\Type\UnionType::class]);
89+
$paramDecorated = \true;
90+
}
91+
if (!$this->isUnionIntersection($functionLike->returnType)) {
92+
if ($paramDecorated) {
93+
return $functionLike;
94+
}
95+
return null;
96+
}
97+
Assert::isInstanceOf($functionLike->returnType, UnionType::class);
98+
$this->phpDocFromTypeDeclarationDecorator->decorateReturn($functionLike);
99+
return $functionLike;
100+
}
101+
private function processClassLike(ClassLike $classLike): ?ClassLike
102+
{
103+
$hasChanged = \false;
104+
foreach ($classLike->getProperties() as $property) {
105+
if (!$this->isUnionIntersection($property->type)) {
106+
continue;
107+
}
108+
Assert::isInstanceOf($property->type, UnionType::class);
109+
$this->propertyDecorator->decorateWithDocBlock($property, $property->type);
110+
$property->type = null;
111+
$hasChanged = \true;
112+
}
113+
return $hasChanged ? $classLike : null;
114+
}
115+
private function isUnionIntersection(?Node $node): bool
116+
{
117+
if (!$node instanceof UnionType) {
118+
return \false;
119+
}
120+
foreach ($node->types as $type) {
121+
if ($type instanceof IntersectionType) {
122+
return \true;
123+
}
124+
}
125+
return \false;
126+
}
127+
}

0 commit comments

Comments
 (0)