It seems like you code against a concrete implementation and not the interface Railt\Parser\Ast\RuleInterface as the method getFullName() does only exist in the following implementations of said interface: Railt\SDL\Frontend\Ast\D...\ArgumentDefinitionNode, Railt\SDL\Frontend\Ast\D...DirectiveDefinitionNode, Railt\SDL\Frontend\Ast\D...tion\EnumDefinitionNode, Railt\SDL\Frontend\Ast\D...EnumValueDefinitionNode, Railt\SDL\Frontend\Ast\D...ion\FieldDefinitionNode, Railt\SDL\Frontend\Ast\D...ion\InputDefinitionNode, Railt\SDL\Frontend\Ast\D...nputFieldDefinitionNode, Railt\SDL\Frontend\Ast\D...InterfaceDefinitionNode, Railt\SDL\Frontend\Ast\D...on\ObjectDefinitionNode, Railt\SDL\Frontend\Ast\D...on\ScalarDefinitionNode, Railt\SDL\Frontend\Ast\D...on\SchemaDefinitionNode, Railt\SDL\Frontend\Ast\D...hemaFieldDefinitionNode, Railt\SDL\Frontend\Ast\D...tion\TypeDefinitionNode, Railt\SDL\Frontend\Ast\D...ion\UnionDefinitionNode.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different implementation
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
It seems like you code against a concrete implementation and not the interface Railt\Parser\Ast\RuleInterface as the method getDescription() does only exist in the following implementations of said interface: Railt\SDL\Frontend\Ast\D...\ArgumentDefinitionNode, Railt\SDL\Frontend\Ast\D...DirectiveDefinitionNode, Railt\SDL\Frontend\Ast\D...tion\EnumDefinitionNode, Railt\SDL\Frontend\Ast\D...EnumValueDefinitionNode, Railt\SDL\Frontend\Ast\D...ion\FieldDefinitionNode, Railt\SDL\Frontend\Ast\D...ion\InputDefinitionNode, Railt\SDL\Frontend\Ast\D...nputFieldDefinitionNode, Railt\SDL\Frontend\Ast\D...InterfaceDefinitionNode, Railt\SDL\Frontend\Ast\D...on\ObjectDefinitionNode, Railt\SDL\Frontend\Ast\D...on\ScalarDefinitionNode, Railt\SDL\Frontend\Ast\D...on\SchemaDefinitionNode, Railt\SDL\Frontend\Ast\D...hemaFieldDefinitionNode, Railt\SDL\Frontend\Ast\D...tion\TypeDefinitionNode, Railt\SDL\Frontend\Ast\D...ion\UnionDefinitionNode.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different implementation
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
It seems like you code against a concrete implementation and not the interface Railt\Parser\Ast\RuleInterface as the method getHintModifiers() does only exist in the following implementations of said interface: Railt\SDL\Frontend\Ast\D...\ArgumentDefinitionNode, Railt\SDL\Frontend\Ast\D...EnumValueDefinitionNode, Railt\SDL\Frontend\Ast\D...ion\FieldDefinitionNode, Railt\SDL\Frontend\Ast\D...nputFieldDefinitionNode, Railt\SDL\Frontend\Ast\D...hemaFieldDefinitionNode.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different implementation
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
It seems like you code against a concrete implementation and not the interface Railt\Parser\Ast\RuleInterface as the method getHintTypeName() does only exist in the following implementations of said interface: Railt\SDL\Frontend\Ast\D...\ArgumentDefinitionNode, Railt\SDL\Frontend\Ast\D...EnumValueDefinitionNode, Railt\SDL\Frontend\Ast\D...ion\FieldDefinitionNode, Railt\SDL\Frontend\Ast\D...nputFieldDefinitionNode, Railt\SDL\Frontend\Ast\D...hemaFieldDefinitionNode.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different implementation
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
$ast of type object<Railt\Parser\Ast\RuleInterface> is not a sub-type of object<Railt\SDL\Fronten...on\FieldDefinitionNode>. It seems like you assume a concrete implementation of the interface Railt\Parser\Ast\RuleInterface 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 $field; (Railt\SDL\IR\TypeDefinition) is incompatible with the return type documented by Railt\SDL\Frontend\Build...ion\FieldBuilder::build of type Generator.
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...
43
}
44
45
/**
46
* @param FieldDefinitionNode $ast
47
* @param TypeDefinition $field
48
* @return \Generator
49
*/
50
protected function loadArguments(FieldDefinitionNode $ast, TypeDefinition $field): \Generator
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: