From 863b3e6bfddc86422a143d21707919ab3d5d48cc Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Mon, 20 Jan 2020 20:40:55 +0100 Subject: [PATCH] Fix AssertChoide with choices --- README.md | 4 +-- .../Constraints/AssertChoiceTagValueNode.php | 10 +++++- .../AssertChoicePhpDocNodeFactory.php | 2 +- .../Fixture/assert_choice.php.inc | 32 +++++++++++++++++++ .../Utils/ArrayItemStaticHelper.php | 5 +++ 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 packages/Php74/tests/Rector/Property/TypedPropertyRector/Fixture/assert_choice.php.inc diff --git a/README.md b/README.md index c5c7e98fe976..2b099b7325aa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/packages/BetterPhpDocParser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php b/packages/BetterPhpDocParser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php index 2dd1c3e5f43f..5cb6632a2a15 100644 --- a/packages/BetterPhpDocParser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php +++ b/packages/BetterPhpDocParser/src/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php @@ -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 @@ public function __toString(): string } else { $contentItems['callback'] = sprintf('callback="%s"', $this->callback); } + } elseif ($this->choices) { + $contentItems[] = $this->printArrayItem($this->choices); } if ($this->strict !== null) { diff --git a/packages/BetterPhpDocParser/src/PhpDocNodeFactory/Symfony/Validator/Constraints/AssertChoicePhpDocNodeFactory.php b/packages/BetterPhpDocParser/src/PhpDocNodeFactory/Symfony/Validator/Constraints/AssertChoicePhpDocNodeFactory.php index cbe0d9d2cc82..4bd5a631621c 100644 --- a/packages/BetterPhpDocParser/src/PhpDocNodeFactory/Symfony/Validator/Constraints/AssertChoicePhpDocNodeFactory.php +++ b/packages/BetterPhpDocParser/src/PhpDocNodeFactory/Symfony/Validator/Constraints/AssertChoicePhpDocNodeFactory.php @@ -36,6 +36,6 @@ public function createFromNodeAndTokens(Node $node, TokenIterator $tokenIterator $annotationContent = $this->resolveContentFromTokenIterator($tokenIterator); - return new AssertChoiceTagValueNode($choice->callback, $choice->strict, $annotationContent); + return new AssertChoiceTagValueNode($choice->callback, $choice->strict, $annotationContent, $choice->choices); } } diff --git a/packages/Php74/tests/Rector/Property/TypedPropertyRector/Fixture/assert_choice.php.inc b/packages/Php74/tests/Rector/Property/TypedPropertyRector/Fixture/assert_choice.php.inc new file mode 100644 index 000000000000..6298a184557d --- /dev/null +++ b/packages/Php74/tests/Rector/Property/TypedPropertyRector/Fixture/assert_choice.php.inc @@ -0,0 +1,32 @@ + +----- + diff --git a/src/BetterPhpDocParser/Utils/ArrayItemStaticHelper.php b/src/BetterPhpDocParser/Utils/ArrayItemStaticHelper.php index c7ec829f4724..6e999535b014 100644 --- a/src/BetterPhpDocParser/Utils/ArrayItemStaticHelper.php +++ b/src/BetterPhpDocParser/Utils/ArrayItemStaticHelper.php @@ -35,6 +35,11 @@ public static function filterAndSortVisibleItems(array $contentItems, array $ord { // 1. remove unused items foreach (array_keys($contentItems) as $key) { + // generic key + if (is_int($key)) { + continue; + } + if (in_array($key, $orderedVisibleItems, true)) { continue; }