| 1 | <?php |
||
| 25 | abstract class AbstractCallableNode extends AbstractNode |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * Constructs a new callable wrapper. |
||
| 29 | * |
||
| 30 | * @param \PDepend\Source\AST\AbstractASTCallable $node |
||
| 31 | */ |
||
| 32 | 68 | public function __construct(AbstractASTCallable $node) |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Returns the number of parameters in the callable signature. |
||
| 39 | * |
||
| 40 | * @return integer |
||
| 41 | */ |
||
| 42 | 2 | public function getParameterCount() |
|
| 46 | } |
||
| 47 |
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: