1 | <?php |
||
31 | class InstructionsRenderer implements InstructionsRendererInterface |
||
32 | { |
||
33 | /** |
||
34 | * Makes the helper setting optional for common use cases |
||
35 | */ |
||
36 | const DEFAULT_DRAW_HELPER = 'WebinoDrawElement'; |
||
37 | |||
38 | /** |
||
39 | * @var HelperPluginManager |
||
40 | */ |
||
41 | protected $drawHelpers; |
||
42 | |||
43 | /** |
||
44 | * @var Locator |
||
45 | */ |
||
46 | protected $locator; |
||
47 | |||
48 | /** |
||
49 | * @var NodeListFactory |
||
50 | */ |
||
51 | protected $nodeListFactory; |
||
52 | |||
53 | /** |
||
54 | * @var InstructionsFactory |
||
55 | */ |
||
56 | protected $instructionsFactory; |
||
57 | |||
58 | /** |
||
59 | * @var ModuleOptions |
||
60 | */ |
||
61 | protected $drawOptions; |
||
62 | |||
63 | /** |
||
64 | * @param object|HelperPluginManager $drawHelpers |
||
65 | * @param Locator $locator |
||
66 | * @param NodeListFactory $nodeListFactory |
||
67 | * @param InstructionsFactory $instructionsFactory |
||
68 | * @param object|ModuleOptions $drawOptions |
||
69 | */ |
||
70 | public function __construct( |
||
83 | |||
84 | /** |
||
85 | * Render the DOMElement ownerDocument |
||
86 | * |
||
87 | * {@inheritDocs} |
||
88 | * @throws InvalidArgumentException |
||
89 | */ |
||
90 | public function render(NodeInterface $node, $instructions, array $vars) |
||
138 | |||
139 | /** |
||
140 | * @param array $specs |
||
141 | * @return array |
||
142 | */ |
||
143 | protected function createNodeSpec(array $specs) |
||
149 | |||
150 | /** |
||
151 | * @param DOMNodeList $nodes |
||
152 | * @param string $helper |
||
153 | * @param array $spec |
||
154 | * @param array $vars |
||
155 | */ |
||
156 | protected function drawNodes(DOMNodeList $nodes, $helper, array $spec, array $vars) |
||
162 | |||
163 | /** |
||
164 | * @param NodeInterface|null $node |
||
165 | * @param array $spec |
||
166 | * @return bool |
||
167 | */ |
||
168 | protected function resolveIsNodeDisabled($node, array $spec) |
||
173 | |||
174 | /** |
||
175 | * @param DOMNodeList|null $nodes |
||
176 | * @return bool |
||
177 | */ |
||
178 | protected function resolveIsEmptyNodes(DOMNodeList $nodes = null) |
||
182 | |||
183 | /** |
||
184 | * @param array|NodeList $nodes |
||
185 | * @param array $instructions |
||
186 | * @param ArrayObject $translation |
||
187 | * @return $this |
||
188 | */ |
||
189 | public function subInstructions($nodes, array $instructions, ArrayObject $translation) |
||
205 | |||
206 | /** |
||
207 | * @param array $spec |
||
208 | * @param Translation $translation |
||
209 | * @return $this |
||
210 | */ |
||
211 | public function expandInstructions(array &$spec, Translation $translation = null) |
||
236 | } |
||
237 |
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: