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

Do not mutate clean up functions #1285

Merged

Conversation

exussum12
Copy link
Contributor

@exussum12 exussum12 commented Jul 28, 2020

Functions like Close and Free should not be removed by the function call
removals. Removing them does not change the tested behavior, but does
free the memory before the script finished / garbage collection is
invoked

This PR:

Copy link
Member

@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please run make cs to fix CS Fixer issues locally?

Saw a couple of such complains on Twitter about fclose and friends, so it makes sense for me.

@maks-rafalko maks-rafalko added this to the 0.17.0 milestone Jul 28, 2020
@maks-rafalko maks-rafalko self-requested a review July 28, 2020 14:05
src/Mutator/Removal/FunctionCallRemoval.php Outdated Show resolved Hide resolved
private $whitelisted = [
'close',
'free',
'free_result',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not terribly excited about a special list for instance methods. I wish we could have this either configurable, or completed with the means supposed to exists under #1231

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was configurable you would need this everywhere ?
How about checking that all of these in the method versions take no argument ? eg $someClass->free() would be ignored but $someClass->free($someVariable) would be allowed to mutate ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing so against native calls is ok but extending it to arbitrary classes is not: a user will likely be able to test that its $someClass->free() is called or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They return void though ? https://www.php.net/manual/en/mysqli-result.free.php or https://www.php.net/manual/en/event.free could check if void return and 0 arguments and called one of these things ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and how do you tell the difference between $mysqliResult->free() and $repository->free()? We do not have type inference at the moment so we cannot distinguish the two and the later may deserve to be covered by infection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree there will be methods missed by doing this, I don't have the stats but most methods I have seen called one of these are methods which have no real observable behaviour.

Could have this as a user config option instead at project level instead of line level ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a user config option for this list is a bad idea.

@exussum12 exussum12 force-pushed the addSomeWhitelistedFunctions branch from 50811d4 to e6b1e06 Compare July 29, 2020 05:23
@exussum12 exussum12 changed the title Add clean up functions to whitelist Do not mutate clean up functions Jul 29, 2020
@maks-rafalko
Copy link
Member

maks-rafalko commented Jul 31, 2020

Since we have different opinions on object's methods calls, here is what I suggest:

  • leave only native functions call ignore list in this PR and merge it
  • think about method calls in a separate issue. But: I recommend to read this thread: Allow adding mutation exclusions for specific calls #697. By implementing the feature that is being discussed there will cover your needs (method calls)

Functions like Close and Free should not be removed by the function call
removals. Removing them does not change the tested behaviour, but does
free the memory before the script finished / garbage collection is
invoked
@exussum12
Copy link
Contributor Author

Since we have different opinions on object's methods calls, here is what I suggest:

Sounds good to me, I have updated the PR to be just the native functions side of things here.

@maks-rafalko maks-rafalko merged commit 2933982 into infection:master Aug 2, 2020
@maks-rafalko
Copy link
Member

Thank you, @exussum12!

@exussum12 exussum12 deleted the addSomeWhitelistedFunctions branch August 2, 2020 16:33
@lcobucci
Copy link
Contributor

Does it make sense to add openssl_free_key() to the list too?

@maks-rafalko
Copy link
Member

sounds good to me. Feel free to open a PR targeted to 0.17, so we will release it ASAP as 0.17.1

@lcobucci lcobucci mentioned this pull request Aug 19, 2020
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants