diff --git a/composer.json b/composer.json index 715e42074..badab3e6b 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "ext-libxml": "*", "composer/xdebug-handler": "^1.3", "justinrainbow/json-schema": "^5.2", - "nikic/php-parser": "^4.1", + "nikic/php-parser": "^4.2.1", "ocramius/package-versions": "^1.2", "padraic/phar-updater": "^1.0.4", "pimple/pimple": "^3.2", diff --git a/composer.lock b/composer.lock index e707095d5..4b264c05a 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "f0460d05acd2ab2a660492a273f482df", + "content-hash": "8af1f24b91068bfac1ba46b2a0fd55f8", "packages": [ { "name": "composer/ca-bundle", @@ -104,7 +104,7 @@ "Xdebug", "performance" ], - "time": "2018-08-31T19:20:00+00:00" + "time": "2018-08-31T19:07:57+00:00" }, { "name": "justinrainbow/json-schema", @@ -174,16 +174,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.1.0", + "version": "v4.2.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "d0230c5c77a7e3cfa69446febf340978540958c0" + "reference": "5221f49a608808c1e4d436df32884cbc1b821ac0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/d0230c5c77a7e3cfa69446febf340978540958c0", - "reference": "d0230c5c77a7e3cfa69446febf340978540958c0", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/5221f49a608808c1e4d436df32884cbc1b821ac0", + "reference": "5221f49a608808c1e4d436df32884cbc1b821ac0", "shasum": "" }, "require": { @@ -199,7 +199,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -221,7 +221,7 @@ "parser", "php" ], - "time": "2018-10-10T09:24:14+00:00" + "time": "2019-02-16T20:54:15+00:00" }, { "name": "ocramius/package-versions", @@ -325,7 +325,7 @@ "homepage": "http://blog.astrumfutura.com" }, { - "name": "Théo Fidry", + "name": "Théo FIDRY", "email": "theo.fidry@gmail.com" } ], diff --git a/src/Mutator/Operator/AssignCoalesce.php b/src/Mutator/Operator/AssignCoalesce.php new file mode 100644 index 000000000..5612379fc --- /dev/null +++ b/src/Mutator/Operator/AssignCoalesce.php @@ -0,0 +1,64 @@ +var, $node->expr, $node->getAttributes()); + } + + protected function mutatesNode(Node $node): bool + { + return $node instanceof Coalesce; + } +} diff --git a/src/Mutator/Util/MutatorProfile.php b/src/Mutator/Util/MutatorProfile.php index 1ccafb00e..619d2a62a 100644 --- a/src/Mutator/Util/MutatorProfile.php +++ b/src/Mutator/Util/MutatorProfile.php @@ -144,6 +144,7 @@ final class MutatorProfile ]; public const OPERATOR = [ + Mutator\Operator\AssignCoalesce::class, Mutator\Operator\Break_::class, Mutator\Operator\Coalesce::class, Mutator\Operator\Continue_::class, @@ -310,6 +311,7 @@ final class MutatorProfile 'OneZeroFloat' => Mutator\Number\OneZeroFloat::class, //Operator + 'AssignCoalesce' => Mutator\Operator\AssignCoalesce::class, 'Break_' => Mutator\Operator\Break_::class, 'Continue_' => Mutator\Operator\Continue_::class, 'Throw_' => Mutator\Operator\Throw_::class, diff --git a/tests/Mutator/Operator/AssignCoalesceTest.php b/tests/Mutator/Operator/AssignCoalesceTest.php new file mode 100644 index 000000000..929fc46c0 --- /dev/null +++ b/tests/Mutator/Operator/AssignCoalesceTest.php @@ -0,0 +1,106 @@ +doTest($input, $expected); + } + + public function provideMutationCases(): \Generator + { + yield 'Mutate coalesce when right part is a scalar value' => [ + <<<'PHP' + [ + <<<'PHP' + [ + <<<'PHP' + [ + <<<'PHP' +