1 | <?php |
||
10 | abstract class AbstractToken implements Token |
||
11 | { |
||
12 | /** @var Configuration */ |
||
13 | protected $configuration; |
||
14 | |||
15 | /** @var int */ |
||
16 | private $depth; |
||
17 | |||
18 | /** @var null|Token */ |
||
19 | private $parent; |
||
20 | |||
21 | /** @var string */ |
||
22 | private $type; |
||
23 | |||
24 | /** |
||
25 | * Constructor |
||
26 | */ |
||
27 | 67 | public function __construct($type, Configuration $configuration, Token $parent = null) |
|
37 | |||
38 | /** |
||
39 | * Required by the Token interface. |
||
40 | */ |
||
41 | 38 | public function getDepth() |
|
45 | |||
46 | /** |
||
47 | * Required by the Token interface. |
||
48 | */ |
||
49 | 19 | public function getParent() |
|
53 | |||
54 | /** |
||
55 | * Chainable setter for 'parent'. |
||
56 | */ |
||
57 | 66 | public function setParent(Token $parent = null) |
|
68 | |||
69 | /** |
||
70 | * Required by the Token interface. |
||
71 | */ |
||
72 | 31 | public function getType() |
|
76 | |||
77 | 67 | protected function isValidType($type) |
|
85 | |||
86 | 48 | public static function cleanChildTokens(Configuration $configuration, array &$children, LoggerInterface $logger = null) |
|
117 | } |
||
118 |
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: