New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement: Implement UnwrapArrayReplace mutator #536
Enhancement: Implement UnwrapArrayReplace mutator #536
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@borNfreee I could imagine that this mutator could create as many mutations as arguments are passed to |
Do you mean this - $d = array_replace(['a'], ['b'], ['c']);
+ $d = ['a'];
+ $d = ['b'];
+ $d = ['c']; ? I didn't do any analyzing but this sounds good to me. |
@borNfreee Exactly! |
So there go mutators for But probably it is not a bad idea to update this mutator to use the current API now, rather than wait for #494. For inspiration see #500. In a nutshell for this to work @@ -50,12 +50,16 @@ abstract class AbstractUnwrapMutator extends Mutator
*/
final public function mutate(Node $node)
{
- return $node->args[$this->getParameterIndex()];
+ foreach ($this->getParameterIndex() as $index) {
+ if (array_key_exists($index, $node->args)) {
+ yield $node->args[$index];
+ }
+ }
}
abstract protected function getFunctionName(): string;
- abstract protected function getParameterIndex(): int;
+ abstract protected function getParameterIndex(): \Generator;
final protected function mutatesNode(Node $node): bool And concrete mutators: - protected function getParameterIndex(): int
+ protected function getParameterIndex(): \Generator
{
- return 0;
+ yield 0;
} Seems doable, what do you think? |
a277384
to
fc786aa
Compare
Absolutely! For now I implemented it for the |
aaa1f75
to
1a90079
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
We should probably merge this one (after resolving conflict) and then rebase #534 to use |
1a90079
to
0a4c2b2
Compare
There's something PHPStan did not like. |
0a4c2b2
to
8ae3963
Compare
8ae3963
to
926477c
Compare
Thank you @localheinz |
Thank you, @borNfreee and @sanmai! |
This PR
UnwrapArrayReplace
mutatorRelated to #514.
πββοΈ Follows the example in #513.