-
Notifications
You must be signed in to change notification settings - Fork 2
Conversation
To clarify, this is about finding calls like |
That is what I understood from looking at it |
|
||
// Should use array_key_exists | ||
in_array( $key, array_keys( $array ) ); | ||
in_array( $key, array_keys ); |
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.
Isn’t this a false positive? array_keys
is not a function call here.
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.
This is intentional. The tokenizer does not know what a function call is. All I can look for is a T_STRING token.
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.
Or a T_STRING token followed by a T_LPAREN or whatever the (
token is called? (Probably with whitespace in between, and comments…)
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.
Sure, but why? What false-positive would that avoid? Bareword strings? ;-)
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.
Okay, fair enough ;)
array_keys( $array ); | ||
array_key_exists( $key, $array ); | ||
in_array( $key ) && array_keys( $array ); | ||
in_array( array_keys( $key ), $array ); |
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.
No tests for array_flip
instead of array_keys
?
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.
Yea, I was a little sloppy. I will add one.
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.
Done.
06af2b0
to
3d549cf
Compare
This doesn’t seem to work inside an public function queryConstraintsForProperty( PropertyId $propertyId ) {
$id = $propertyId->getSerialization();
if ( !in_array( $id, array_keys( $this->cache ) ) ) {
$this->cache[$id] = $this->lookup->queryConstraintsForProperty( $propertyId );
}
return $this->cache[$id];
} No warning on this code. (If I copy one of the failing lines from the tests here into the file, it triggers an error, so I know the sniffer runs.) |
3d549cf
to
0bfd0da
Compare
I found the issue and fixed the sniff. Awesome you found this! |
Cool, thanks! Let’s merge :) |
Custom sniff that finds unnecessary slow in_array() that can be replaced with array_key_exists() or isset().
Pinging @legoktm as he might be interested.