Skip to content

Commit 9f65b28

Browse files
committed
[Analyzer] Trim SimpleType to used API: drop describe()/getClassName(), add variadic isInstanceOf()
- SimpleTypeInterface is now a marker (no describe()) - ObjectType exposes only isInstanceOf(string ...$classNames), exact match - rules use isInstanceOf() instead of getClassName() comparisons - unit test asserts by concrete type instead of describe()
1 parent f41e25c commit 9f65b28

11 files changed

Lines changed: 17 additions & 45 deletions

File tree

‎rules/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector.php‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
*/
3232
final class RemoveReflectionSetAccessibleCallsRector extends AbstractRector implements MinPhpVersionInterface
3333
{
34-
/**
35-
* @var string[]
36-
*/
37-
private const array REFLECTION_CLASSES = ['ReflectionProperty', 'ReflectionMethod'];
38-
3934
public function __construct(
4035
private readonly SimpleScopeResolver $simpleScopeResolver
4136
) {
@@ -128,6 +123,6 @@ private function isReflectionSetAccessibleCall(Node $node, SimpleScope $simpleSc
128123
return false;
129124
}
130125

131-
return in_array($simpleType->getClassName(), self::REFLECTION_CLASSES, true);
126+
return $simpleType->isInstanceOf('ReflectionProperty', 'ReflectionMethod');
132127
}
133128
}

‎rules/Simple/Rector/ClassMethod/DemoObjectMethodCallRenameRector.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function refactorMethodCall(Node $node, SimpleScope $simpleScope): bool
104104
return false;
105105
}
106106

107-
if ($simpleType->getClassName() !== self::TARGET_CLASS) {
107+
if (! $simpleType->isInstanceOf(self::TARGET_CLASS)) {
108108
return false;
109109
}
110110

‎src/Analyzer/SimpleType/ArrayType.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@
88

99
final class ArrayType implements SimpleTypeInterface
1010
{
11-
public function describe(): string
12-
{
13-
return 'array';
14-
}
1511
}

‎src/Analyzer/SimpleType/BooleanType.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@
88

99
final class BooleanType implements SimpleTypeInterface
1010
{
11-
public function describe(): string
12-
{
13-
return 'bool';
14-
}
1511
}

‎src/Analyzer/SimpleType/Contract/SimpleTypeInterface.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace Rector\Analyzer\SimpleType\Contract;
66

7-
// PHPStan-free type contract, resolved by SimpleScope
7+
// PHPStan-free type marker, resolved by SimpleScope
88
interface SimpleTypeInterface
99
{
10-
public function describe(): string;
1110
}

‎src/Analyzer/SimpleType/IntegerType.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@
88

99
final class IntegerType implements SimpleTypeInterface
1010
{
11-
public function describe(): string
12-
{
13-
return 'int';
14-
}
1511
}

‎src/Analyzer/SimpleType/MixedType.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@
88

99
final class MixedType implements SimpleTypeInterface
1010
{
11-
public function describe(): string
12-
{
13-
return 'mixed';
14-
}
1511
}

‎src/Analyzer/SimpleType/NullType.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@
88

99
final class NullType implements SimpleTypeInterface
1010
{
11-
public function describe(): string
12-
{
13-
return 'null';
14-
}
1511
}

‎src/Analyzer/SimpleType/ObjectType.php‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@ public function __construct(
1313
) {
1414
}
1515

16-
public function describe(): string
16+
// exact class match; SimpleScope has no reflection, so no parent/interface check
17+
public function isInstanceOf(string ...$classNames): bool
1718
{
18-
return $this->className;
19-
}
20-
21-
public function getClassName(): string
22-
{
23-
return $this->className;
19+
return in_array($this->className, $classNames, true);
2420
}
2521
}

‎src/Analyzer/SimpleType/StringType.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@
88

99
final class StringType implements SimpleTypeInterface
1010
{
11-
public function describe(): string
12-
{
13-
return 'string';
14-
}
1511
}

0 commit comments

Comments
 (0)