Skip to content

Commit

Permalink
[PHP 8.0] Fix skip of silent key in annotation to attribute (#1932)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Mar 15, 2022
1 parent b835233 commit dc8e8ff
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/PhpAttribute/AttributeArrayNameInliner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Exception\NotImplementedYetException;
use Webmozart\Assert\Assert;

final class AttributeArrayNameInliner
Expand Down Expand Up @@ -66,6 +67,11 @@ private function inlineArray(array $args): array
if ($arrayItem->key instanceof String_) {
$arrayItemString = $arrayItem->key;
$newArgs[] = new Arg($arrayItem->value, false, false, [], new Identifier($arrayItemString->value));
} elseif ($arrayItem->key === null) {
// silent key
$newArgs[] = new Arg($arrayItem->value);
} else {
throw new NotImplementedYetException(get_debug_type($arrayItem->key));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture;

use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\GenericAnnotation;

/**
* @GenericAnnotation("sample", itemOperations="yes")
*/
final class FirstParamIsSilent
{
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture;

use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\GenericAnnotation;

#[GenericAnnotation('sample', itemOperations: 'yes')]
final class FirstParamIsSilent
{
}

?>

0 comments on commit dc8e8ff

Please sign in to comment.