information about instance of variable not used
Code Example
<?php
declare(strict_types=1);
class Element {
public function get(): int {
return 0;
}
}
class Test {
private $arr = [];
public function test($key) {
if (isset($this->arr[$key]) && $this->arr[$key] instanceof Element) {
return $this->arr[$key]->get();
}
}
}
Actual Behavior
ERROR Call to undefined method {}->get()
Expected Behavior
All ok
Environment
- NoVerify Version: dev-master
Yes, linter does not support <expression> instanceof Class, it only works in one specific case which is $var instanceof Class. I am not sure I want to support arbitrary expressions here (yet).
Interestingly enough, PHPStorm does not support this either :). But I think that it is possible to implement in linter, I will try to do it.
So this should work now :). It is not the best implementation possible, e.g. in this example I do not analyze that you do not change value of $key between checking instanceof and calling the method. I just match the whole expression and if it is identical to what was previously checked, then it will work.
Wow, thanks :)