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
Implement UnwrapArrayMap and UnwrapArrayFilter mutators #513
Conversation
return $node->args[$this->getParameterIndex()]; | ||
} | ||
|
||
protected function mutatesNode(Node $node): bool |
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.
Shouldn't this be final, what do you think?
protected function mutatesNode(Node $node): bool | |
final protected function mutatesNode(Node $node): bool |
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.
Definietly :)
* | ||
* @return Node\Param; | ||
*/ | ||
public function mutate(Node $node) |
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.
public function mutate(Node $node) | |
final public function mutate(Node $node) |
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.
Outside of some minor comments, looks good to me.
<<<'PHP' | ||
<?php | ||
|
||
$a = array_filter(['A', 1, 'C'], function($var): bool { |
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.
could you please add more tests (like parameter as a variable, function with lower/upper cased characters and so on.)
See the list of cases in https://github.com/infection/infection/blob/68f70ad62ffd14af62781d989e4230c45c235010/tests/Mutator/Regex/PregQuoteTest.php
same for array_map
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.
Nice catch, wrongly capitalized was the problem :)
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.
There's $node->name->toLowerString()
of use.
PHP | ||
]; | ||
|
||
yield 'It mutates correctly when array_map is wrongly capitalized' => [ |
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.
yield 'It mutates correctly when array_map is wrongly capitalized' => [ | |
yield 'It mutates correctly when array_filter is wrongly capitalized' => [ |
PHP | ||
]; | ||
|
||
yield 'It mutates correctly when array_map uses another function as input' => [ |
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.
yield 'It mutates correctly when array_map uses another function as input' => [ | |
yield 'It mutates correctly when array_filter uses another function as input' => [ |
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.
Cool 👍
Can we restart CI jobs? |
Thank you @akondas, nice work. The build is green now |
@akondas can I ask you to update documentation, please? See infection/site#70 |
I just realized that with this new base abstract class, we can implement not only array functions mutators as mentioned here, but for any other function, for example - return strtolower($string);
+ return $string; 👍 |
Yeah, and things like: - return array_reduce($array, $func, $initial);
+ return $initial; Should we make a list within an issue with ideas? |
good idea, done #514 |
@@ -159,6 +160,11 @@ | |||
Mutator\Cast\CastString::class, | |||
]; | |||
|
|||
public const UNWRAP = [ | |||
Mutator\Unwrap\UnwrapArrayMap::class, | |||
Mutator\Unwrap\UnwrapArrayFilter::class, |
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.
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.
Same order as in the manual should work best, IMO.
|
||
// Unwrap | ||
'UnwrapArrayMap' => Mutator\Unwrap\UnwrapArrayMap::class, | ||
'UnwrapArrayFilter' => Mutator\Unwrap\UnwrapArrayFilter::class, |
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.
* Implement UnwrapArrayMap and UnwrapArrayFilter mutators * Add more tests examples and fix wrongly capitalized funcation name * Fix typos in tests provider for UnwrapArrayFilter mutator
This PR:
AbstractUnwrapMutator
UnwrapArrayFilter
andUnwrapArrayMap
mutatorsInspiration in #490
Fixes #490