It seems like you code against a specific sub-type and not the parent class ReflectionMethod as the method getAnnotation() does only exist in the following sub-classes of ReflectionMethod: Ray\Aop\ReflectionMethod. 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.
The property Ray\AuraSqlModule\Annotation\Transactional::$value has been deprecated.
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be
removed from the class and what other property to use instead.
Loading history...
35
3
return (new PropTransaction)($invocation, $transactional);
36
}
37
if (! $this->pdo instanceof ExtendedPdoInterface) {
38
return $invocation->proceed();
39
}
40
try {
41
$this->pdo->beginTransaction();
42
$result = $invocation->proceed();
43
$this->pdo->commit();
44
} catch (\PDOException $e) {
45
$this->pdo->rollBack();
46
throw new RollbackException($e->getMessage(), 0, $e);
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: