Php-cs-fixer: Fixer that makes some conditions more strict

Created on 31 Jan 2018  路  9Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

I stumbled upon this recommendation: https://github.com/wata727/pahout/blob/master/docs/LooseReturnCheck.md
I think it would be nice to have a fixer for those cases.

kinfeature request

Most helpful comment

I'm kinda 馃憥 for this. Maybe it would be nice to have this fixer (though I'm not sure it would be in all cases) but as @keradus said, the benefit would be small while implementing and maintening the fixer would require extra work. Proper tests should be enough to spot such cases.

All 9 comments

basically, what methods shall be checked?
that could be tricky.
if i get it right, it's about having boolean as condition, not mixed.
so if confition is foo() that foo: mixed, then we want to convert it to some boolean expression, like bar !== foo().
then, figure out what could be foo and respective bar for them...

@keradus The link above talks about strpos(), mb_strpos(), stripos(), mb_stripos(), strrpos(), mb_strrpos(), and array_search(). Their bar is false.

that's my point. this list is out of the blue. Why only those functions? why not, for example, preg_match ?

@keradus A positive result of preg_match is always truthy (1), but a positive result of the above functions could be falsy (0).

That list of functions is not exhaustive, there may be other functions that have a similar signature that could lead to bugs when using loose checking.

Fixing some cases is better than not fixing any.

I must admit that I don't see big benefit of fixing only some of them.

@keradus Small benefit is better than no benefit :wink:

I'm kinda 馃憥 for this. Maybe it would be nice to have this fixer (though I'm not sure it would be in all cases) but as @keradus said, the benefit would be small while implementing and maintening the fixer would require extra work. Proper tests should be enough to spot such cases.

I'm going to close this one after the discussion.
Feel free to keep the discussion going and we can always reopen!
btw. the initial link is now dead so it is kind of hard to follow the request now

They removed this check: https://github.com/wata727/pahout/pull/47/files#diff-d85284893e1054e0c96d70013e48275e

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fisharebest picture fisharebest  路  3Comments

vitek-rostislav picture vitek-rostislav  路  3Comments

BackEndTea picture BackEndTea  路  3Comments

EvgenyOrekhov picture EvgenyOrekhov  路  3Comments

Bilge picture Bilge  路  3Comments