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" }, 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' +