1 | <?php |
||
24 | final class TwigFileExtractor extends AbstractExtension implements FileExtractor |
||
25 | { |
||
26 | /** |
||
27 | * @var NodeVisitorInterface[] |
||
28 | */ |
||
29 | private $visitors = []; |
||
30 | |||
31 | /** |
||
32 | * @var Environment |
||
33 | */ |
||
34 | private $twig; |
||
35 | |||
36 | 5 | public function __construct(Environment $twig) |
|
41 | |||
42 | 5 | public function getSourceLocations(SplFileInfo $file, SourceCollection $collection): void |
|
53 | |||
54 | 1 | public function getType(): string |
|
58 | |||
59 | 5 | public function addVisitor(NodeVisitorInterface $visitor): void |
|
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 5 | public function getNodeVisitors(): array |
|
71 | |||
72 | public function getName(): string |
||
76 | } |
||
77 |
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: