-
-
Notifications
You must be signed in to change notification settings - Fork 166
Add negation mutators #1753
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
Add negation mutators #1753
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.
Sorry for the delay in the review; good job! 👏
Despite the number of comments I think it's mostly nitpicks, it looks pretty good to me.
It's been too long since I've had a good view on the mutators and I didn't completely follow the conversation with @maks-rafalko previously neither so I do think it deserve another round of review. As such I wouldn't recommend to address all the points yet just in case another maintainer disagrees with them :)
<<<'PHP' | ||
<?php | ||
|
||
$var = a() && b(); |
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.
just for the sake of it I would add another test making use of the and
and AND
notation instead of &&
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.
I think that require implementation of \PhpParser\Node\Expr\BinaryOp\LogicalAnd
node in mutators. Currently, we operate on BooleanAnd
node.
{ | ||
private function isSimpleExpression(Node\Expr $expr): bool | ||
{ | ||
return $expr instanceof Node\Expr\FuncCall |
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.
looking at the implementation the method could be static
/** | ||
* @internal | ||
8000 | */ | |
trait SimpleExpression |
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.
From this alone I am not convinced there is any benefit of it being a trait. It could very well be a regular stateless class with a static method and a private constructor.
But maybe the rest of the team prefers traits... I'll let them voice their opinion on it
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.
I agree with you, I also prefer working with static methods that with traits. Making it static class require to write unit tests for it (project requirement). So let me know which way I supposed to choose ;)
|| $expr instanceof Node\Expr\StaticCall | ||
|| $expr instanceof Node\Expr\Variable | ||
|| $expr instanceof Node\Expr\ArrayDimFetch | ||
|| $expr instanceof Node\Expr\ClassConstFetch; |
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.
Note for other reviewers, I did not verify the list completeness
Thank you for review @theofidry I've introducer some of changes proposed by you and I'm waiting for comments from another reviewers:) |
Hi @maks-rafalko, any updates on this PR? :) |
Oh, somehow I missed this one, sorry. Could you please rebase so we can move forward? And thank you for you patience and work! |
Co-authored-by: Théo FIDRY <5175937+theofidry@users.noreply.github.com>
Co-authored-by: Théo FIDRY <5175937+theofidry@users.noreply.github.com>
Co-authored-by: Théo FIDRY <5175937+theofidry@users.noreply.github.com>
6a1ca8c
to
71b2fb9
Compare
Ok, I managed to rebase it myself. Notes for reviewers: we need to analyze if the provided mutators somehow generate duplicate muations (with existing in My idea is to create boolean matrices (as I did here #1752 (comment)) and compare all of them, finding duplicate results. |
Just out of curiosity as I don't know the full functionality behind. Isn't there a hashmap containing a list of, let's say, md5 hashes of the content of each mutated file? So that there can be no duplicate mutation? Or is it because that some mutations look different but produce the same logical outcome? |
@icanhazstring I'm more about boolean matrices created by new mutators here. The simplest thing to understand it is De Morgan's law where However, your question about hashes gives some source for thinking. We do have md5 hashing for each mutation, but I don't think we check uniqueness to avoid duplicates on physical, not logical level: infection/src/Mutation/Mutation.php Lines 173 to 186 in 0228b46
|
Maybe we could improve this hash based on the uniqueness of these logical mutations? |
…utate identical expressions
…f abstract methods
…tate identical expressions with boolean ($a === false), because it's same as TrueValue/FalseValue
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.
@manhunto this is absolutely awesome work. I've spent this day investigating the code and checking for duplicates. Made and update to not negate $a === false & $b !== true
because it's duplicate of TrueValue
/ FalseValue
mutators. Did the same for Or
analogue.
Also, added more tests and simplified child classes to reduce the number of abstract methods.
I agree that from maintenance POV it's better to keep classes separate, at least for now, because the logic is quite complex.
Thank you for your great contribution, going to merge it as soon as the build passes.
@maks-rafalko thank you for helping me with this PR -- for the changes you introduced in this PR and docs :) |
This PR:
if
andelse if
(it only mutates simple expressions like function call, method call etc. to not duplicate with other existing mutators)LogicalAnd
andLogicalOr
expressionsLogicalAnd
andLogicalOr
expressions (even in complex conditions)LogicalAnd
andLogicalOr
expressions (even in complex conditions, only simple sub expressions like inif
andelse if
)I've decided to create one PR for all mutators because they are related. They share traits and I think it is better to review it together, but I can split it if you think that it will be easier to maintain.
Closes: #1752