-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PHP 8.1] Do not process static methods from Enum class (#2911)
* Do not process static methods from Enum class * Properly handle case where result of the method is further accessed (chain call). * keep FQN class names by convention * [ci-review] Rector Rectify Co-authored-by: xrogers <xrogers@gmail.com> Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
edf1d52
commit f230e54
Showing
5 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
.../MethodCall/MyCLabsMethodCallToEnumConstRector/Fixture/fully_qualified_class_name.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Fixture; | ||
|
||
use \Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector; | ||
|
||
final class FullyQualifiedClassName | ||
{ | ||
public function run($value) | ||
{ | ||
$compare = \Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Source\SomeEnum::USED_TO_BE_CONST(); | ||
$compare2 = MyCLabsMethodCallToEnumConstRector\Source\SomeEnum::USED_TO_BE_CONST(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Fixture; | ||
|
||
use \Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector; | ||
|
||
final class FullyQualifiedClassName | ||
{ | ||
public function run($value) | ||
{ | ||
$compare = \Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Source\SomeEnum::USED_TO_BE_CONST; | ||
$compare2 = \Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Source\SomeEnum::USED_TO_BE_CONST; | ||
} | ||
} | ||
|
||
?> |
21 changes: 21 additions & 0 deletions
21
...ethodCall/MyCLabsMethodCallToEnumConstRector/Fixture/skip_enum_static_method_call.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Fixture; | ||
|
||
use Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Source\SomeEnum; | ||
|
||
final class StaticEnumStaticMethodCall | ||
{ | ||
public function run($value) | ||
{ | ||
SomeEnum::from($value)->getKey(); | ||
SomeEnum::from($value)->getValue(); | ||
$compare = SomeEnum::from($value); | ||
$compare = SomeEnum::values(); | ||
$compare = SomeEnum::keys(); | ||
$compare = SomeEnum::isValid($value); | ||
$compare = SomeEnum::search($value); | ||
$compare = SomeEnum::toArray(); | ||
SomeEnum::assertValidValue($value); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...1/Rector/MethodCall/MyCLabsMethodCallToEnumConstRector/Fixture/usage_of_get_value.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Fixture; | ||
|
||
use Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Source\SomeEnum; | ||
|
||
final class UsageOfGetValue | ||
{ | ||
public function run($value) | ||
{ | ||
$enum = SomeEnum::USED_TO_BE_CONST()->getValue(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Fixture; | ||
|
||
use Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Source\SomeEnum; | ||
|
||
final class UsageOfGetValue | ||
{ | ||
public function run($value) | ||
{ | ||
$enum = \Rector\Tests\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector\Source\SomeEnum::USED_TO_BE_CONST->value; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters