It seems like you code against a concrete implementation and not the interface Railt\Parser\Ast\NodeInterface as the method first() does only exist in the following implementations of said interface: Railt\Compiler\Grammar\P...legate\BaseRuleDelegate, Railt\Compiler\Grammar\P...e\ConcatenationDelegate, Railt\Compiler\Grammar\P...elegate\IncludeDelegate, Railt\Compiler\Grammar\P...gate\InvocationDelegate, Railt\Compiler\Grammar\P...ragmaDefinitionDelegate, Railt\Compiler\Grammar\P...gate\RepetitionDelegate, Railt\Compiler\Grammar\PP2\Delegate\RuleDelegate, Railt\Compiler\Grammar\P...TokenDefinitionDelegate, Railt\Parser\Ast\Rule.
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\NodeInterface as the method first() does only exist in the following implementations of said interface: Railt\Compiler\Grammar\P...legate\BaseRuleDelegate, Railt\Compiler\Grammar\P...e\ConcatenationDelegate, Railt\Compiler\Grammar\P...elegate\IncludeDelegate, Railt\Compiler\Grammar\P...gate\InvocationDelegate, Railt\Compiler\Grammar\P...ragmaDefinitionDelegate, Railt\Compiler\Grammar\P...gate\RepetitionDelegate, Railt\Compiler\Grammar\PP2\Delegate\RuleDelegate, Railt\Compiler\Grammar\P...TokenDefinitionDelegate, Railt\Parser\Ast\Rule.
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\NodeInterface as the method first() does only exist in the following implementations of said interface: Railt\Compiler\Grammar\P...legate\BaseRuleDelegate, Railt\Compiler\Grammar\P...e\ConcatenationDelegate, Railt\Compiler\Grammar\P...elegate\IncludeDelegate, Railt\Compiler\Grammar\P...gate\InvocationDelegate, Railt\Compiler\Grammar\P...ragmaDefinitionDelegate, Railt\Compiler\Grammar\P...gate\RepetitionDelegate, Railt\Compiler\Grammar\PP2\Delegate\RuleDelegate, Railt\Compiler\Grammar\P...TokenDefinitionDelegate, Railt\Parser\Ast\Rule.
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.
The method getRule does only exist in Railt\Compiler\Grammar\PP2\Delegate\ProvidesSymbol, but not in Railt\Parser\Ast\NodeInterface.
It seems like the method you are trying to call exists only in some of the
possible types.
Let’s take a look at an example:
classA{publicfunctionfoo(){}}classBextendsA{publicfunctionbar(){}}/** * @param A|B $x */functionsomeFunction($x){$x->foo();// This call is fine as the method exists in A and B.$x->bar();// This method only exists in B and might cause an error.}
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: