Skip to content

Commit 3142e04

Browse files
committed
[TypeDeclaration] Split ParamTypeByMethodCallTypeRector into Object, Scalar and Array rules
Extract shared engine into AbstractParamTypeByMethodCallTypeRector; each concrete rule owns a disjoint param type group via isMatchingParamType(): - ObjectParamTypeByMethodCallTypeRector - object types (incl. nullable) - ScalarParamTypeByMethodCallTypeRector - scalar types (string/int/float/bool) - ArrayParamTypeByMethodCallTypeRector - array types (incl. nullable) - ParamTypeByMethodCallTypeRector - remaining compound (cross-group unions, iterable, callable) Types are null-stripped first, so nullable variants route to their group.
1 parent dce1bcb commit 3142e04

38 files changed

Lines changed: 906 additions & 356 deletions

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"files": [
101101
"tests/debug_functions.php",
102102
"rules-tests/Transform/Rector/FuncCall/FuncCallToMethodCallRector/Source/some_view_function.php",
103-
"rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Source/FunctionTyped.php",
103+
"rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Source/FunctionTyped.php",
104104
"rules-tests/TypeDeclaration/Rector/StmtsAwareInterface/SafeDeclareStrictTypesRector/Source/functions.php",
105105
"rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Source/ParentClass.php"
106106
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class ArrayParamTypeByMethodCallTypeRectorTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector\Fixture;
4+
5+
final class NullableArray
6+
{
7+
public function go($value)
8+
{
9+
$this->use($value);
10+
}
11+
12+
private function use(?array $value): void
13+
{
14+
}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector\Fixture;
22+
23+
final class NullableArray
24+
{
25+
public function go(?array $value)
26+
{
27+
$this->use($value);
28+
}
29+
30+
private function use(?array $value): void
31+
{
32+
}
33+
}
34+
35+
?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector\Fixture;
4+
5+
use stdClass;
6+
7+
final class SkipObjectType
8+
{
9+
public function go($value)
10+
{
11+
$this->use($value);
12+
}
13+
14+
private function use(stdClass $value): void
15+
{
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector\Fixture;
4+
5+
final class SkipScalarType
6+
{
7+
public function go($value)
8+
{
9+
$this->use($value);
10+
}
11+
12+
private function use(string $value): void
13+
{
14+
}
15+
}

rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/throw_without_new.php.inc renamed to rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/throw_without_new.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Fixture;
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector\Fixture;
44

55
final class ThrowWithoutNew
66
{
@@ -20,7 +20,7 @@ final class ThrowWithoutNew
2020
-----
2121
<?php
2222

23-
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Fixture;
23+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector\Fixture;
2424

2525
final class ThrowWithoutNew
2626
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector;
7+
use Rector\ValueObject\PhpVersion;
8+
9+
return RectorConfig::configure()
10+
->withRules([ArrayParamTypeByMethodCallTypeRector::class])
11+
->withPhpVersion(PhpVersion::PHP_80);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ObjectParamTypeByMethodCallTypeRector\Fixture;
4+
5+
use stdClass;
6+
7+
final class NullableObjectParam
8+
{
9+
public function go($value)
10+
{
11+
$this->use($value);
12+
}
13+
14+
private function use(?stdClass $value): void
15+
{
16+
}
17+
}
18+
19+
?>
20+
-----
21+
<?php
22+
23+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ObjectParamTypeByMethodCallTypeRector\Fixture;
24+
25+
use stdClass;
26+
27+
final class NullableObjectParam
28+
{
29+
public function go(?\stdClass $value)
30+
{
31+
$this->use($value);
32+
}
33+
34+
private function use(?stdClass $value): void
35+
{
36+
}
37+
}
38+
39+
?>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ObjectParamTypeByMethodCallTypeRector\Fixture;
4+
5+
use stdClass;
6+
7+
final class ObjectParam
8+
{
9+
public function go($value)
10+
{
11+
$this->use($value);
12+
}
13+
14+
private function use(stdClass $value): void
15+
{
16+
}
17+
}
18+
19+
?>
20+
-----
21+
<?php
22+
23+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ObjectParamTypeByMethodCallTypeRector\Fixture;
24+
25+
use stdClass;
26+
27+
final class ObjectParam
28+
{
29+
public function go(\stdClass $value)
30+
{
31+
$this->use($value);
32+
}
33+
34+
private function use(stdClass $value): void
35+
{
36+
}
37+
}
38+
39+
?>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ObjectParamTypeByMethodCallTypeRector\Fixture;
4+
5+
final class SkipArrayType
6+
{
7+
public function go($value)
8+
{
9+
$this->use($value);
10+
}
11+
12+
private function use(array $value): void
13+
{
14+
}
15+
}

0 commit comments

Comments
 (0)