Infection: Family mb_*-functions mutators

Created on 8 Mar 2019  路  5Comments  路  Source: infection/infection

It is common to see people use multibyte string functions (like mb_strlen) instead of their common analogs (like strlen), while not writing any tests exploiting multibyte functionality.

In this situations mutators as simple as below could be of use:

- if (mb_strlen($str) < 10) {
+ if (strlen($str) < 10) {

And similar mutators for functions like mb_substr, and others.

(This mutator could simply check if a function call starts with mb_, and then replace the function name with a prefix-less function if it exists, though this may not be the best approach.)

Feature Request RFC

Most helpful comment

Funny I already have this mutator stashed on mine laptop ;-) Will create PR when I get back to home

All 5 comments

This mutator could simply check if a function call starts with mb_, and then replace the function name with a prefix-less function if it exists, though this may not be the best approach

I'd prefer to have a map which holds mb_ function names as key, and non mb_ variants as the value, and then we simply check if the function name is a key in the map, and replace it with the value.

Great idea.

As I understand, both your implementation suggestions mean we will have 1 mutator class that mutates N functions, right?

In this case, we need settings to be able to disable any of the function mutations.

Funny I already have this mutator stashed on mine laptop ;-) Will create PR when I get back to home

As the PR is merged do we closes the issue ?

BTW thanks for great feedback during review.

Sure, should be closed

BTW, if the Fixes #654 had been used instead of Relates to issue #654, this issue would have been closed automatically (also, the bot would have added needed labels automatically).

Thanks for adding this feature, nice contribution!

Was this page helpful?
0 / 5 - 0 ratings