1 | <?php |
||
11 | abstract class AbstractToken implements Token |
||
12 | { |
||
13 | /** @var Configuration */ |
||
14 | protected $configuration; |
||
15 | |||
16 | /** @var int */ |
||
17 | private $depth; |
||
18 | |||
19 | /** @var null|Token */ |
||
20 | private $parent; |
||
21 | |||
22 | /** |
||
23 | * Constructor |
||
24 | */ |
||
25 | 112 | public function __construct(Configuration $configuration) |
|
31 | |||
32 | /** |
||
33 | * Required by the Token interface. |
||
34 | */ |
||
35 | 84 | public function getDepth() |
|
39 | |||
40 | /** |
||
41 | * Required by the Token interface. |
||
42 | */ |
||
43 | 54 | public function getParent() |
|
47 | |||
48 | /** |
||
49 | * Chainable setter for 'parent'. |
||
50 | */ |
||
51 | 83 | public function setParent(Token $parent = null) |
|
62 | |||
63 | 5 | public function hasAncestor(Element $element) |
|
76 | |||
77 | 89 | public static function cleanChildTokens(Configuration $configuration, array &$children, LoggerInterface $logger) |
|
94 | |||
95 | abstract public function getType(); |
||
96 | |||
97 | 12 | public function __toString() |
|
101 | } |
||
102 |
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: