$command of type object<hiapi\commands\EntityCommandInterface> is not a sub-type of object<hiapi\commands\EntityCommand>. It seems like you assume a concrete implementation of the interface hiapi\commands\EntityCommandInterface to be always present.
This check looks for parameters that are defined as one type in their type
hint or doc comment but seem to be used as a narrower type, i.e an
implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming
your parameter is of the expected type.
The return type of return $this->getReposit...ecification($command)); (false|object) is incompatible with the return type of the parent method hiapi\commands\SearchHandler::handle of type object[].
If you return a value from a function or method, it should be a sub-type of the
type that is given by the parent type f.e. an interface, or abstract method.
This is more formally defined by the
Lizkov substitution principle,
and guarantees that classes that depend on the parent type can use any instance
of a child type interchangably. This principle also belongs to the
SOLID principles
for object oriented design.
Our function my_function expects a Post object, and outputs the author
of the post. The base class Post returns a simple string and outputting a
simple string will work just fine. However, the child class BlogPost which
is a sub-type of Post instead decided to return an object, and is
therefore violating the SOLID principles. If a BlogPost were passed to
my_function, PHP would not complain, but ultimately fail when executing the
strtoupper call in its body.
Loading history...
27
}
28
29
protected function buildSpecification(EntityCommandInterface $command)
Accessing id on the interface hiapi\commands\EntityCommandInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a
concrete implementation of the interface.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.