From 204a2827951de3bd0a65f99fa14f02224a6f19be Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 5 Mar 2024 19:19:48 +0100 Subject: [PATCH 1/5] Handle NeverType https://github.com/BenSampo/laravel-enum/issues/355 --- src/Rector/ToNativeRector.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Rector/ToNativeRector.php b/src/Rector/ToNativeRector.php index 6c19524..941fe0e 100644 --- a/src/Rector/ToNativeRector.php +++ b/src/Rector/ToNativeRector.php @@ -4,6 +4,7 @@ use Illuminate\Support\Arr; use PhpParser\Node; +use PHPStan\Type\NeverType; use PHPStan\Type\ObjectType; use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\PhpParser\Node\Value\ValueResolver; @@ -36,6 +37,10 @@ public function configure(array $configuration): void protected function inConfiguredClasses(Node $node): bool { + if ($this->getType($node) instanceof NeverType) { + return false; + } + foreach ($this->classes as $class) { if ($this->isObjectType($node, $class)) { return true; From 567529d01a132e6cf3a26570ed68ccf55be9e30b Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Fri, 8 Mar 2024 15:32:14 +0100 Subject: [PATCH 2/5] never --- src/Rector/ToNativeRector.php | 6 ++++-- tests/Rector/ToNativeUsagesRectorTest.php | 1 + tests/Rector/Usages/never.php.inc | 11 +++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/Rector/Usages/never.php.inc diff --git a/src/Rector/ToNativeRector.php b/src/Rector/ToNativeRector.php index 941fe0e..750fc49 100644 --- a/src/Rector/ToNativeRector.php +++ b/src/Rector/ToNativeRector.php @@ -4,7 +4,7 @@ use Illuminate\Support\Arr; use PhpParser\Node; -use PHPStan\Type\NeverType; +use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\ObjectType; use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\PhpParser\Node\Value\ValueResolver; @@ -37,7 +37,9 @@ public function configure(array $configuration): void protected function inConfiguredClasses(Node $node): bool { - if ($this->getType($node) instanceof NeverType) { + // I don't understand why, but get_class() is used in concat: '' . get_class(0) + // Somehow isObjectType produces true - thus leading rector to make this: '' . get_class(ß)->value + if ($this->getType($node) instanceof ConstantBooleanType) { return false; } diff --git a/tests/Rector/ToNativeUsagesRectorTest.php b/tests/Rector/ToNativeUsagesRectorTest.php index 325f463..7b62e78 100644 --- a/tests/Rector/ToNativeUsagesRectorTest.php +++ b/tests/Rector/ToNativeUsagesRectorTest.php @@ -16,6 +16,7 @@ public function test(string $filePath): void /** @return iterable */ public static function provideData(): iterable { + yield [__DIR__. '/Usages/never.php.inc']; return self::yieldFilesFromDirectory(__DIR__ . '/Usages'); } diff --git a/tests/Rector/Usages/never.php.inc b/tests/Rector/Usages/never.php.inc new file mode 100644 index 0000000..6804d16 --- /dev/null +++ b/tests/Rector/Usages/never.php.inc @@ -0,0 +1,11 @@ + Date: Fri, 8 Mar 2024 15:32:23 +0100 Subject: [PATCH 3/5] format --- tests/Rector/ToNativeUsagesRectorTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Rector/ToNativeUsagesRectorTest.php b/tests/Rector/ToNativeUsagesRectorTest.php index 7b62e78..0f889cb 100644 --- a/tests/Rector/ToNativeUsagesRectorTest.php +++ b/tests/Rector/ToNativeUsagesRectorTest.php @@ -16,7 +16,8 @@ public function test(string $filePath): void /** @return iterable */ public static function provideData(): iterable { - yield [__DIR__. '/Usages/never.php.inc']; + yield [__DIR__ . '/Usages/never.php.inc']; + return self::yieldFilesFromDirectory(__DIR__ . '/Usages'); } From a5b2e53f8679d26a07438a54b865eca06822e220 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Fri, 8 Mar 2024 15:32:39 +0100 Subject: [PATCH 4/5] fix --- tests/Rector/ToNativeUsagesRectorTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Rector/ToNativeUsagesRectorTest.php b/tests/Rector/ToNativeUsagesRectorTest.php index 0f889cb..325f463 100644 --- a/tests/Rector/ToNativeUsagesRectorTest.php +++ b/tests/Rector/ToNativeUsagesRectorTest.php @@ -16,8 +16,6 @@ public function test(string $filePath): void /** @return iterable */ public static function provideData(): iterable { - yield [__DIR__ . '/Usages/never.php.inc']; - return self::yieldFilesFromDirectory(__DIR__ . '/Usages'); } From 3c6437a15b6d3b8f7046ae993df32412c31786b0 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Fri, 8 Mar 2024 15:37:11 +0100 Subject: [PATCH 5/5] cl --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7128c00..a673c1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## 6.10.1 + +### Fixed + +- Avoid false-positive addition of `->value` in `enum:to-native` + +## 6.10.0 + +### Added + +- Allow installation alongside PHPUnit 11 + ## 6.9.1 ### Fixed