1 | <?php |
||
29 | class CommonPointCut |
||
30 | { |
||
31 | /** @var MethodInterceptor */ |
||
32 | protected $interceptor; |
||
33 | |||
34 | /** @var string */ |
||
35 | protected $annotation; |
||
36 | |||
37 | /** |
||
38 | * @param MethodInterceptor $interceptor |
||
39 | */ |
||
40 | protected function setInterceptor(MethodInterceptor $interceptor): void |
||
44 | |||
45 | /** |
||
46 | * @return Pointcut |
||
47 | */ |
||
48 | protected function withAnnotatedAnyInterceptor(): PointCut |
||
60 | } |
||
61 |
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: