Skip to content

Commit

Permalink
[Transform] Handle crash string in EnumCase on StringToClassConstantR…
Browse files Browse the repository at this point in the history
…ector (#2680)
  • Loading branch information
samsonasik committed Jul 18, 2022
1 parent c9ecc86 commit a66e653
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Enum_;
use PhpParser\Node\Stmt\EnumCase;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Finally_;
use PhpParser\Node\Stmt\Foreach_;
Expand Down Expand Up @@ -110,7 +111,12 @@ public function processNodes(
$isScopeRefreshing,
$smartFileInfo
): void {
if (($node instanceof Expression || $node instanceof Return_) && $node->expr instanceof Expr) {
if ((
$node instanceof Expression ||
$node instanceof Return_ ||
$node instanceof Assign ||
$node instanceof EnumCase
) && $node->expr instanceof Expr) {
$node->expr->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}

Expand Down Expand Up @@ -149,7 +155,6 @@ public function processNodes(

if ($node instanceof Assign) {
// decorate value as well
$node->expr->setAttribute(AttributeKey::SCOPE, $mutatingScope);
$node->var->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Rector\Tests\Transform\Rector\String_\StringToClassConstantRector\Fixture;

enum SkipNotFoundInEnumCase: string
{
case A = 'a';
}

0 comments on commit a66e653

Please sign in to comment.