From c07d50787a50f4735532859a957de69ebf7b901c Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Sun, 18 Oct 2020 00:55:10 +0900 Subject: [PATCH 1/2] Introduce YieldValue mutator --- src/Mutator/ProfileList.php | 2 + src/Mutator/ReturnValue/YieldValue.php | 82 ++++++++++++++++++ .../Mutator/ReturnValue/YieldValueTest.php | 84 +++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 src/Mutator/ReturnValue/YieldValue.php create mode 100644 tests/phpunit/Mutator/ReturnValue/YieldValueTest.php diff --git a/src/Mutator/ProfileList.php b/src/Mutator/ProfileList.php index 376f4008d..f28224250 100644 --- a/src/Mutator/ProfileList.php +++ b/src/Mutator/ProfileList.php @@ -180,6 +180,7 @@ final class ProfileList Mutator\ReturnValue\IntegerNegation::class, Mutator\ReturnValue\NewObject::class, Mutator\ReturnValue\This::class, + Mutator\ReturnValue\YieldValue::class, ]; public const SORT_PROFILE = [ @@ -364,6 +365,7 @@ final class ProfileList 'IntegerNegation' => Mutator\ReturnValue\IntegerNegation::class, 'NewObject' => Mutator\ReturnValue\NewObject::class, 'This' => Mutator\ReturnValue\This::class, + 'YieldValue' => Mutator\ReturnValue\YieldValue::class, // Sort 'Spaceship' => Mutator\Sort\Spaceship::class, diff --git a/src/Mutator/ReturnValue/YieldValue.php b/src/Mutator/ReturnValue/YieldValue.php new file mode 100644 index 000000000..2377177c6 --- /dev/null +++ b/src/Mutator/ReturnValue/YieldValue.php @@ -0,0 +1,82 @@ + $value`) yielded value with the yielded value only; +For example `yield $b->bar;`. +TXT + , + MutatorCategory::ORTHOGONAL_REPLACEMENT, + null + ); + } + + /** + * @param Node\Expr\Yield_ $node + * + * @return iterable + */ + public function mutate(Node $node): iterable + { + $node->key = null; + + yield $node; + } + + public function canMutate(Node $node): bool + { + return $node instanceof Node\Expr\Yield_ && $node->key; + } +} diff --git a/tests/phpunit/Mutator/ReturnValue/YieldValueTest.php b/tests/phpunit/Mutator/ReturnValue/YieldValueTest.php new file mode 100644 index 000000000..4cab1d9db --- /dev/null +++ b/tests/phpunit/Mutator/ReturnValue/YieldValueTest.php @@ -0,0 +1,84 @@ +doTest($input, $expected); + } + + public function mutationsProvider(): iterable + { + yield 'It mutates a yield with key and value to a yield with a value only' => [ + <<<'PHP' + $b); +}; +PHP + , + <<<'PHP' + [ + <<<'PHP' + Date: Sun, 18 Oct 2020 11:06:36 +0900 Subject: [PATCH 2/2] Updat schema.json --- resources/schema.json | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/schema.json b/resources/schema.json index 319dc5013..2c7ef0c82 100644 --- a/resources/schema.json +++ b/resources/schema.json @@ -216,6 +216,7 @@ ] }, "Yield_": { "$ref": "#/definitions/default-mutator-config" }, + "YieldValue": { "$ref": "#/definitions/default-mutator-config" }, "GreaterThan": { "$ref": "#/definitions/default-mutator-config" }, "GreaterThanOrEqualTo": { "$ref": "#/definitions/default-mutator-config" }, "LessThan": { "$ref": "#/definitions/default-mutator-config" },