Fix AssertChoide with choices

This commit is contained in:
TomasVotruba 2020-01-20 20:40:55 +01:00
parent c43094213b
commit 863b3e6bfd
5 changed files with 49 additions and 4 deletions

View File

@ -70,9 +70,9 @@ Tip: If you have EasyCodingStandard, you can start your set with [`ecs-after-rec
## Try Rector Online
Too litle time to download?
Too litle time to download?
We have **[online demo](https://getrector.org/demo) just for you!**
We have **[online demo](https://getrector.org/demo) just for you!**
## Install

View File

@ -29,14 +29,20 @@ final class AssertChoiceTagValueNode extends AbstractConstraintTagValueNode
*/
private $strict;
/**
* @var array|null
*/
private $choices;
/**
* @param mixed[]|string|null $callback
*/
public function __construct($callback, ?bool $strict, string $annotationContent)
public function __construct($callback, ?bool $strict, string $annotationContent, ?array $choices)
{
$this->callback = $callback;
$this->strict = $strict;
$this->resolveOriginalContentSpacingAndOrder($annotationContent);
$this->choices = $choices;
}
public function __toString(): string
@ -49,6 +55,8 @@ final class AssertChoiceTagValueNode extends AbstractConstraintTagValueNode
} else {
$contentItems['callback'] = sprintf('callback="%s"', $this->callback);
}
} elseif ($this->choices) {
$contentItems[] = $this->printArrayItem($this->choices);
}
if ($this->strict !== null) {

View File

@ -36,6 +36,6 @@ final class AssertChoicePhpDocNodeFactory extends AbstractPhpDocNodeFactory
$annotationContent = $this->resolveContentFromTokenIterator($tokenIterator);
return new AssertChoiceTagValueNode($choice->callback, $choice->strict, $annotationContent);
return new AssertChoiceTagValueNode($choice->callback, $choice->strict, $annotationContent, $choice->choices);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Symfony\Component\Validator\Constraints as Assert;
class AssertChoice
{
/**
* @var string
* @Assert\Choice({"chalet", "apartment"})
*/
public $type;
}
?>
-----
<?php
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Symfony\Component\Validator\Constraints as Assert;
class AssertChoice
{
/**
* @Assert\Choice({"chalet", "apartment"})
*/
public string $type;
}
?>

View File

@ -35,6 +35,11 @@ final class ArrayItemStaticHelper
{
// 1. remove unused items
foreach (array_keys($contentItems) as $key) {
// generic key
if (is_int($key)) {
continue;
}
if (in_array($key, $orderedVisibleItems, true)) {
continue;
}