phpinspectionsea icon indicating copy to clipboard operation
phpinspectionsea copied to clipboard

[FP] Callable parameter usage violates definition: instanceof issue

Open orklah opened this issue 5 years ago • 1 comments

Subject Details
Plugin Php Inspections (EA Ultimate) last version

Current behaviour

Hi,

In our project, we have a structure of classes and interfaces like this:

interface Vehicle {

}

abstract class Car implements Vehicle{

}

interface ElectricVehicle extends Vehicle{

}

class ElectricCar extends Car implements ElectricVehicle{

}


function foo(Car $car)
{
    if ($car instanceof ElectricVehicle) {}
    //elseif($car instanceof GasVehicle){}
    //elseif($car instanceof NuclearVehicle){}
}

The check with instanceof throws a warning "It seems to be always false (classes are not related)." The classes are not directly related but Car is abstract so it will never be sent "as is". When we look at the example, the child of Car is ElectricCar, which implements ElectricVehicle.

It is kinda related with https://github.com/kalessil/phpinspectionsea/issues/902

Maybe this will be difficult to solve. In this case, is it possible to add a settings to disable this specific check?

Thanks

orklah avatar Apr 23 '19 17:04 orklah

I think this is related, if not Il make an separate issue. php_instanceof_class_and_interface

get the above error from this row: if($exception instanceof \RuntimeException && !$exception instanceof HttpExceptionInterface) {

Trying to exclude HttpException from the test of RuntimeException. class HttpException extends \RuntimeException implements HttpExceptionInterface

  • \RuntimeException
  • \Symfony\Component\HttpKernel\Exception\HttpException
  • \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface

puggan avatar Oct 15 '19 01:10 puggan