Skip to content

Commit 9e281ca

Browse files
authored
Make php artisan enum:to-native compatible with rector 0.19
1 parent 9cd6875 commit 9e281ca

11 files changed

+39
-66
lines changed

.github/workflows/continuous-integration.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
os: [ubuntu-latest]
13-
php: [8.0, 8.1]
13+
php: [8.0, 8.1, 8.2, 8.3]
1414
dependency-versions: [lowest, highest]
1515

1616
name: Tests - P${{ matrix.php }} - ${{ matrix.dependency-versions }} - ${{ matrix.os }}
1717

1818
steps:
19-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v4
2020

2121
- uses: shivammathur/setup-php@v2
2222
with:
@@ -41,13 +41,13 @@ jobs:
4141
strategy:
4242
fail-fast: false
4343
matrix:
44-
php: [8.0, 8.1]
44+
php: [8.0, 8.1, 8.2, 8.3]
4545
dependency-versions: [lowest, highest]
4646

4747
name: Static Analysis - P${{ matrix.php }} - ${{ matrix.dependency-versions }}
4848

4949
steps:
50-
- uses: actions/checkout@v2
50+
- uses: actions/checkout@v4
5151

5252
- uses: shivammathur/setup-php@v2
5353
with:

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## 6.8.0
11+
12+
### Changed
13+
14+
- Make `php artisan enum:to-native` compatible with rector `0.19`
15+
1016
## 6.7.0
1117

1218
### Added

composer.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636
"ergebnis/composer-normalize": "^2.28.3",
3737
"mll-lab/php-cs-fixer-config": "^5.4",
3838
"mockery/mockery": "^1.5",
39-
"nunomaduro/larastan": "^2.6.3",
39+
"larastan/larastan": "^2.6.3",
4040
"orchestra/testbench": "^7.6.1 || ^8",
4141
"phpstan/phpstan": "^1.8.2",
42+
"phpstan/extension-installer": "^1",
4243
"phpstan/phpstan-mockery": "^1.1",
4344
"phpstan/phpstan-phpunit": "^1.1.1",
4445
"phpunit/phpunit": "^9.5.21 || ^10",
45-
"rector/rector": "^0.17.6",
46-
"symplify/rule-doc-generator": "^11"
46+
"rector/rector": "^0.19",
47+
"symplify/rule-doc-generator": "^11 || ^12"
4748
},
4849
"minimum-stability": "dev",
4950
"prefer-stable": true,
@@ -59,7 +60,8 @@
5960
},
6061
"config": {
6162
"allow-plugins": {
62-
"ergebnis/composer-normalize": true
63+
"ergebnis/composer-normalize": true,
64+
"phpstan/extension-installer": true
6365
},
6466
"sort-packages": true
6567
},

phpstan.neon

-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
includes:
22
- extension.neon
3-
- vendor/nunomaduro/larastan/extension.neon
4-
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
5-
- vendor/phpstan/phpstan-mockery/extension.neon
6-
- vendor/phpstan/phpstan-phpunit/extension.neon
7-
- vendor/phpstan/phpstan-phpunit/rules.neon
83
parameters:
94
level: 6 # TODO level up to max
105
paths:

rector-rules.md

-36
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,6 @@ Convert usages of `BenSampo\Enum\Enum` to native PHP enums
88

99
- class: [`BenSampo\Enum\Rector\ToNativeImplementationRector`](src/Rector/ToNativeImplementationRector.php)
1010

11-
```php
12-
<?php
13-
14-
declare(strict_types=1);
15-
16-
use BenSampo\Enum\Rector\ToNativeImplementationRector;
17-
use BenSampo\Enum\Tests\Enums\UserType;
18-
use Rector\Config\RectorConfig;
19-
20-
return static function (RectorConfig $rectorConfig): void {
21-
$rectorConfig->ruleWithConfiguration(ToNativeImplementationRector::class, [
22-
UserType::class,
23-
]);
24-
};
25-
```
26-
27-
28-
2911
```diff
3012
-/**
3113
- * @method static static ADMIN()
@@ -53,24 +35,6 @@ Convert usages of `BenSampo\Enum\Enum` to native PHP enums
5335

5436
- class: [`BenSampo\Enum\Rector\ToNativeUsagesRector`](src/Rector/ToNativeUsagesRector.php)
5537

56-
```php
57-
<?php
58-
59-
declare(strict_types=1);
60-
61-
use BenSampo\Enum\Rector\ToNativeUsagesRector;
62-
use BenSampo\Enum\Tests\Enums\UserType;
63-
use Rector\Config\RectorConfig;
64-
65-
return static function (RectorConfig $rectorConfig): void {
66-
$rectorConfig->ruleWithConfiguration(ToNativeUsagesRector::class, [
67-
UserType::class,
68-
]);
69-
};
70-
```
71-
72-
73-
7438
```diff
7539
-$user = UserType::ADMIN();
7640
-$user->is(UserType::ADMIN);

src/Attributes/Description.php

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace BenSampo\Enum\Attributes;
44

5-
use Attribute;
6-
75
#[\Attribute(\Attribute::TARGET_CLASS_CONSTANT | \Attribute::TARGET_CLASS)]
86
class Description
97
{

src/PHPStan/UniqueValuesRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function processNode(Node $node, Scope $scope): array
3535
foreach ($constants as $name => $value) {
3636
$constantsWithValue = array_filter($constants, fn (mixed $v): bool => $v === $value);
3737
if (count($constantsWithValue) > 1) {
38-
$duplicateConstants []= array_keys($constantsWithValue);
38+
$duplicateConstants[] = array_keys($constantsWithValue);
3939
}
4040
}
4141
$duplicateConstants = array_unique($duplicateConstants);

src/Rector/ToNativeImplementationRector.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@
1414
use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode;
1515
use PHPStan\Type\ObjectType;
1616
use PHPStan\Type\Type;
17+
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1718
use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter;
1819
use Rector\NodeTypeResolver\Node\AttributeKey;
20+
use Rector\PhpParser\Node\Value\ValueResolver;
1921
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
2022
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2123

22-
/**
23-
* @see \BenSampo\Enum\Tests\Rector\ToNativeRectorImplementationTest
24-
*/
24+
/** @see \BenSampo\Enum\Tests\Rector\ToNativeRectorImplementationTest */
2525
class ToNativeImplementationRector extends ToNativeRector
2626
{
2727
public function __construct(
2828
protected PhpDocInfoPrinter $phpDocInfoPrinter,
29+
protected PhpDocInfoFactory $phpDocInfoFactory,
30+
protected ValueResolver $valueResolver,
2931
) {}
3032

3133
public function getRuleDefinition(): RuleDefinition

src/Rector/ToNativeRector.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use PhpParser\Node;
66
use PHPStan\Type\ObjectType;
7-
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
8-
use Rector\Core\Rector\AbstractRector;
7+
use Rector\Contract\Rector\ConfigurableRectorInterface;
8+
use Rector\Rector\AbstractRector;
99

1010
/**
1111
* Conversion of enums and their usages can not be done in a single run of Rector,

src/Rector/ToNativeUsagesRector.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@
5151
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
5252
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
5353

54-
/**
55-
* @see \BenSampo\Enum\Tests\Rector\ToNativeRectorUsagesTest
56-
*/
54+
/** @see \BenSampo\Enum\Tests\Rector\ToNativeRectorUsagesTest */
5755
class ToNativeUsagesRector extends ToNativeRector
5856
{
5957
public const COMPARED_AGAINST_ENUM_INSTANCE = ToNativeUsagesRector::class . '@compared-against-enum-instance';

tests/Rector/Usages/assign.php.inc

+14-6
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,40 @@
22

33
use BenSampo\Enum\Tests\Enums\UserType;
44

5-
/** @var UserType|null $maybeUserType */
6-
75
class Foo {
86
public UserType $userType;
97
}
108

9+
/** @var UserType|null $maybeUserType */
1110
$foo = $maybeUserType ?? UserType::Administrator();
11+
(new Foo)->userType = UserType::Administrator();
12+
$foo = new Foo;
13+
$foo->userType = UserType::Administrator();
14+
/** @var UserType $userType */
15+
$userType = UserType::Administrator();
16+
1217
$qux = UserType::Administrator;
1318
$bar ??= UserType::Administrator;
1419
$baz .= UserType::Administrator;
1520
$ref &= UserType::Administrator;
16-
(new Foo)->userType = UserType::Administrator;
1721
-----
1822
<?php
1923

2024
use BenSampo\Enum\Tests\Enums\UserType;
2125

22-
/** @var UserType|null $maybeUserType */
23-
2426
class Foo {
2527
public UserType $userType;
2628
}
2729

30+
/** @var UserType|null $maybeUserType */
2831
$foo = $maybeUserType ?? UserType::Administrator;
32+
(new Foo)->userType = UserType::Administrator;
33+
$foo = new Foo;
34+
$foo->userType = UserType::Administrator;
35+
/** @var UserType $userType */
36+
$userType = UserType::Administrator;
37+
2938
$qux = UserType::Administrator->value;
3039
$bar ??= UserType::Administrator->value;
3140
$baz .= UserType::Administrator->value;
3241
$ref &= UserType::Administrator->value;
33-
(new Foo)->userType = UserType::Administrator;

0 commit comments

Comments
 (0)