1 | <?php |
||
21 | final class TwigFileExtractor extends \Twig_Extension implements FileExtractor |
||
22 | { |
||
23 | /** |
||
24 | * @var Visitor[]|\Twig_NodeVisitorInterface[] |
||
25 | */ |
||
26 | private $visitors = []; |
||
27 | |||
28 | /** |
||
29 | * @var \Twig_Environment |
||
30 | */ |
||
31 | private $twig; |
||
32 | |||
33 | /** |
||
34 | * @param \Twig_Environment $twig |
||
35 | */ |
||
36 | 6 | public function __construct(\Twig_Environment $twig) |
|
41 | |||
42 | 6 | public function getSourceLocations(SplFileInfo $file, SourceCollection $collection) |
|
43 | { |
||
44 | 6 | foreach ($this->visitors as $v) { |
|
45 | 6 | $v->init($collection, $file); |
|
|
|||
46 | } |
||
47 | |||
48 | 6 | $path = $file->getRelativePath(); |
|
49 | |||
50 | 6 | if (class_exists('Twig_Source')) { |
|
51 | // Twig 2.0 |
||
52 | 6 | $stream = $this->twig->tokenize(new \Twig_Source($file->getContents(), $file->getRelativePathname(), $path)); |
|
53 | } else { |
||
54 | $stream = $this->twig->tokenize($file->getContents(), $path); |
||
55 | } |
||
56 | 6 | $this->twig->parse($stream); |
|
57 | 6 | } |
|
58 | |||
59 | 1 | public function getType() |
|
63 | |||
64 | /** |
||
65 | * @param \Twig_NodeVisitorInterface $visitor |
||
66 | */ |
||
67 | 6 | public function addVisitor(\Twig_NodeVisitorInterface $visitor) |
|
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | 6 | public function getNodeVisitors() |
|
79 | |||
80 | public function getName() |
||
84 | } |
||
85 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: