diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 5ef63e2d..0cde952c 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -10,13 +10,13 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.0, 8.1] + php: [8.0, 8.1, 8.2, 8.3] dependency-versions: [lowest, highest] name: Tests - P${{ matrix.php }} - ${{ matrix.dependency-versions }} - ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: @@ -41,13 +41,13 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0, 8.1] + php: [8.0, 8.1, 8.2, 8.3] dependency-versions: [lowest, highest] name: Static Analysis - P${{ matrix.php }} - ${{ matrix.dependency-versions }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b27cd0d..7584dade 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## 6.8.0 + +### Changed + +- Make `php artisan enum:to-native` compatible with rector `0.19` + ## 6.7.0 ### Added diff --git a/composer.json b/composer.json index 762fcbef..fa04ee7c 100644 --- a/composer.json +++ b/composer.json @@ -36,14 +36,15 @@ "ergebnis/composer-normalize": "^2.28.3", "mll-lab/php-cs-fixer-config": "^5.4", "mockery/mockery": "^1.5", - "nunomaduro/larastan": "^2.6.3", + "larastan/larastan": "^2.6.3", "orchestra/testbench": "^7.6.1 || ^8", "phpstan/phpstan": "^1.8.2", + "phpstan/extension-installer": "^1", "phpstan/phpstan-mockery": "^1.1", "phpstan/phpstan-phpunit": "^1.1.1", "phpunit/phpunit": "^9.5.21 || ^10", - "rector/rector": "^0.17.6", - "symplify/rule-doc-generator": "^11" + "rector/rector": "^0.19", + "symplify/rule-doc-generator": "^11 || ^12" }, "minimum-stability": "dev", "prefer-stable": true, @@ -59,7 +60,8 @@ }, "config": { "allow-plugins": { - "ergebnis/composer-normalize": true + "ergebnis/composer-normalize": true, + "phpstan/extension-installer": true }, "sort-packages": true }, diff --git a/phpstan.neon b/phpstan.neon index d58182b4..4c2fedfb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,10 +1,5 @@ includes: - extension.neon -- vendor/nunomaduro/larastan/extension.neon -- vendor/phpstan/phpstan/conf/bleedingEdge.neon -- vendor/phpstan/phpstan-mockery/extension.neon -- vendor/phpstan/phpstan-phpunit/extension.neon -- vendor/phpstan/phpstan-phpunit/rules.neon parameters: level: 6 # TODO level up to max paths: diff --git a/rector-rules.md b/rector-rules.md index 7cd1785e..a60fba4e 100644 --- a/rector-rules.md +++ b/rector-rules.md @@ -8,24 +8,6 @@ Convert usages of `BenSampo\Enum\Enum` to native PHP enums - class: [`BenSampo\Enum\Rector\ToNativeImplementationRector`](src/Rector/ToNativeImplementationRector.php) -```php -ruleWithConfiguration(ToNativeImplementationRector::class, [ - UserType::class, - ]); -}; -``` - -↓ - ```diff -/** - * @method static static ADMIN() @@ -53,24 +35,6 @@ Convert usages of `BenSampo\Enum\Enum` to native PHP enums - class: [`BenSampo\Enum\Rector\ToNativeUsagesRector`](src/Rector/ToNativeUsagesRector.php) -```php -ruleWithConfiguration(ToNativeUsagesRector::class, [ - UserType::class, - ]); -}; -``` - -↓ - ```diff -$user = UserType::ADMIN(); -$user->is(UserType::ADMIN); diff --git a/src/Attributes/Description.php b/src/Attributes/Description.php index 7c326f28..ca17177d 100644 --- a/src/Attributes/Description.php +++ b/src/Attributes/Description.php @@ -2,8 +2,6 @@ namespace BenSampo\Enum\Attributes; -use Attribute; - #[\Attribute(\Attribute::TARGET_CLASS_CONSTANT | \Attribute::TARGET_CLASS)] class Description { diff --git a/src/PHPStan/UniqueValuesRule.php b/src/PHPStan/UniqueValuesRule.php index 6bf8ab79..8841f289 100644 --- a/src/PHPStan/UniqueValuesRule.php +++ b/src/PHPStan/UniqueValuesRule.php @@ -35,7 +35,7 @@ public function processNode(Node $node, Scope $scope): array foreach ($constants as $name => $value) { $constantsWithValue = array_filter($constants, fn (mixed $v): bool => $v === $value); if (count($constantsWithValue) > 1) { - $duplicateConstants []= array_keys($constantsWithValue); + $duplicateConstants[] = array_keys($constantsWithValue); } } $duplicateConstants = array_unique($duplicateConstants); diff --git a/src/Rector/ToNativeImplementationRector.php b/src/Rector/ToNativeImplementationRector.php index 556b0d48..feb98dca 100644 --- a/src/Rector/ToNativeImplementationRector.php +++ b/src/Rector/ToNativeImplementationRector.php @@ -14,18 +14,20 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter; use Rector\NodeTypeResolver\Node\AttributeKey; +use Rector\PhpParser\Node\Value\ValueResolver; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; -/** - * @see \BenSampo\Enum\Tests\Rector\ToNativeRectorImplementationTest - */ +/** @see \BenSampo\Enum\Tests\Rector\ToNativeRectorImplementationTest */ class ToNativeImplementationRector extends ToNativeRector { public function __construct( protected PhpDocInfoPrinter $phpDocInfoPrinter, + protected PhpDocInfoFactory $phpDocInfoFactory, + protected ValueResolver $valueResolver, ) {} public function getRuleDefinition(): RuleDefinition diff --git a/src/Rector/ToNativeRector.php b/src/Rector/ToNativeRector.php index c29cdbab..6c0e0f82 100644 --- a/src/Rector/ToNativeRector.php +++ b/src/Rector/ToNativeRector.php @@ -4,8 +4,8 @@ use PhpParser\Node; use PHPStan\Type\ObjectType; -use Rector\Core\Contract\Rector\ConfigurableRectorInterface; -use Rector\Core\Rector\AbstractRector; +use Rector\Contract\Rector\ConfigurableRectorInterface; +use Rector\Rector\AbstractRector; /** * Conversion of enums and their usages can not be done in a single run of Rector, diff --git a/src/Rector/ToNativeUsagesRector.php b/src/Rector/ToNativeUsagesRector.php index cda2f3e1..1eec0dfb 100644 --- a/src/Rector/ToNativeUsagesRector.php +++ b/src/Rector/ToNativeUsagesRector.php @@ -51,9 +51,7 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; -/** - * @see \BenSampo\Enum\Tests\Rector\ToNativeRectorUsagesTest - */ +/** @see \BenSampo\Enum\Tests\Rector\ToNativeRectorUsagesTest */ class ToNativeUsagesRector extends ToNativeRector { public const COMPARED_AGAINST_ENUM_INSTANCE = ToNativeUsagesRector::class . '@compared-against-enum-instance'; diff --git a/tests/Rector/Usages/assign.php.inc b/tests/Rector/Usages/assign.php.inc index 88d9f125..647fe562 100644 --- a/tests/Rector/Usages/assign.php.inc +++ b/tests/Rector/Usages/assign.php.inc @@ -2,32 +2,40 @@ use BenSampo\Enum\Tests\Enums\UserType; -/** @var UserType|null $maybeUserType */ - class Foo { public UserType $userType; } +/** @var UserType|null $maybeUserType */ $foo = $maybeUserType ?? UserType::Administrator(); +(new Foo)->userType = UserType::Administrator(); +$foo = new Foo; +$foo->userType = UserType::Administrator(); +/** @var UserType $userType */ +$userType = UserType::Administrator(); + $qux = UserType::Administrator; $bar ??= UserType::Administrator; $baz .= UserType::Administrator; $ref &= UserType::Administrator; -(new Foo)->userType = UserType::Administrator; ----- userType = UserType::Administrator; +$foo = new Foo; +$foo->userType = UserType::Administrator; +/** @var UserType $userType */ +$userType = UserType::Administrator; + $qux = UserType::Administrator->value; $bar ??= UserType::Administrator->value; $baz .= UserType::Administrator->value; $ref &= UserType::Administrator->value; -(new Foo)->userType = UserType::Administrator;