Skip to content
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

Argument removal mutators #537

Open
4 tasks
sanmai opened this issue Oct 31, 2018 · 3 comments
Open
4 tasks

Argument removal mutators #537

sanmai opened this issue Oct 31, 2018 · 3 comments

Comments

@sanmai
Copy link
Member

sanmai commented Oct 31, 2018

There is a lot of functions in PHP that take a variable number of arguments. They ought to be mutated. For example, like so:

- $basket = array_replace($base, $replacements, $replacements2);
+ $basket = array_replace($base, $replacements);

And:

- $basket = array_replace($base, $replacements, $replacements2);
+ $basket = array_replace($base, $replacements2);

Obviously these have to be yield mutators, as implemented in #450, or planned to be implemented in #494. Similarly to #514 these mutators may enjoy own separate profile.

@sanmai sanmai changed the title Argument drop mutatiors Argument drop mutators Oct 31, 2018
@sanmai sanmai changed the title Argument drop mutators Argument removal mutators Nov 1, 2018
@localheinz
Copy link
Member

@sanmai

What do you think, should we remove all combinations? For example

$merged = array_merge($a, $b, $c);

becomes

$merged = array_merge($a);
$merged = array_merge($b);
$merged = array_merge($c);
$merged = array_merge($a, $b);
$merged = array_merge($a, $c);
$merged = array_merge($b, $c);

?

@sanmai
Copy link
Member Author

sanmai commented Nov 5, 2018

These are almost duplicates to what a mutator from #514 will do.

$merged = array_merge($a);
$merged = array_merge($b);
$merged = array_merge($c);

E.g. the latter is same as $merged = $c with a sole exception of array_merge being used for its renumbering side-effect. But against that side-effect $merged = $c mutation is even better. So, yeah, there got to be a solid case for these mutations to exist. I can't think of one yet.

These below look totally sensible to me:

$merged = array_merge($a, $b);
$merged = array_merge($a, $c);
$merged = array_merge($b, $c);

@sanmai
Copy link
Member Author

sanmai commented Nov 8, 2018

Using all possible combinations of arguments not only somewhat burdensome to implement and test, but also can lead to an exponential growth of mutants to tests. Say, you have an array_merge() call with 5 arguments. That's 15 combinations... Or 2 ** n - 1 for n=4, speaking of formulas. For 10 arguments, if we'd happen to find them, which is not an impossible event, it'll be 1023 extra mutant to test, just out of the thin air, for a single mutator. Now consider if we add a couple of such mutators... Will they all worth it? Hard to say.

So I think best would be not to diverge into things exponential and keep to removal of arguments, only, for time being.

On a side note, I can't remember if we can add comment nodes, yet think we should be able to, but commenting out a removed argument seems prettier than just to remove:

-$merged = array_merge($a, $b, $c);
+$merged = array_merge($a, /*$b,*/ $c);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants