It seems like you code against a specific sub-type and not the parent class mcorten87\rabbitmq_api\jobs\JobBase as the method getVirtualHost() does only exist in the following sub-classes of mcorten87\rabbitmq_api\jobs\JobBase: mcorten87\rabbitmq_api\j...BetweenQueueAndExchange, mcorten87\rabbitmq_api\jobs\JobBindingListExchange, mcorten87\rabbitmq_api\jobs\JobBindingListQueue, mcorten87\rabbitmq_api\j...bBindingListVirtualHost, mcorten87\rabbitmq_api\j...BindingToExchangeCreate, mcorten87\rabbitmq_api\j...BindingToExchangeDelete, mcorten87\rabbitmq_api\j...JobBindingToQueueCreate, mcorten87\rabbitmq_api\j...JobBindingToQueueDelete, mcorten87\rabbitmq_api\j...nnectionListVirtualHost, mcorten87\rabbitmq_api\j...finitionListVirtualHost, mcorten87\rabbitmq_api\jobs\JobExchangeCreate, mcorten87\rabbitmq_api\jobs\JobExchangeDelete, mcorten87\rabbitmq_api\jobs\JobExchangeList, mcorten87\rabbitmq_api\j...ExchangeListVirtualHost, mcorten87\rabbitmq_api\jobs\JobExchangePublish, mcorten87\rabbitmq_api\jobs\JobPermissionCreate, mcorten87\rabbitmq_api\jobs\JobPermissionDelete, mcorten87\rabbitmq_api\j...rmissionListVirtualHost, mcorten87\rabbitmq_api\jobs\JobQueueCreate, mcorten87\rabbitmq_api\jobs\JobQueueDelete, mcorten87\rabbitmq_api\jobs\JobQueueList, mcorten87\rabbitmq_api\j...JobQueueListVirtualHost, mcorten87\rabbitmq_api\jobs\JobVirtualHostCreate, mcorten87\rabbitmq_api\jobs\JobVirtualHostDelete, mcorten87\rabbitmq_api\jobs\JobVirtualHostList. Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example:
abstractclassUser{/** @return string */abstractpublicfunctiongetPassword();}classMyUserextendsUser{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 sub-classes
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 specific sub-type and not the parent class mcorten87\rabbitmq_api\jobs\JobBase as the method getUser() does only exist in the following sub-classes of mcorten87\rabbitmq_api\jobs\JobBase: mcorten87\rabbitmq_api\jobs\JobPermissionCreate, mcorten87\rabbitmq_api\jobs\JobPermissionDelete, mcorten87\rabbitmq_api\jobs\JobPermissionListUser, mcorten87\rabbitmq_api\jobs\JobUserCreate, mcorten87\rabbitmq_api\jobs\JobUserDelete, mcorten87\rabbitmq_api\jobs\JobUserList. Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example:
abstractclassUser{/** @return string */abstractpublicfunctiongetPassword();}classMyUserextendsUser{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 sub-classes
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.
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 sub-classes 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 parent class: