1 | <?php |
||
25 | final class PHPFileExtractor implements FileExtractor |
||
26 | { |
||
27 | /** |
||
28 | * @var Visitor[]|NodeVisitor[] |
||
29 | */ |
||
30 | private $visitors = []; |
||
31 | |||
32 | 21 | public function getSourceLocations(SplFileInfo $file, SourceCollection $collection) |
|
33 | { |
||
34 | 21 | $path = $file->getRelativePath(); |
|
35 | 21 | $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); |
|
36 | 21 | $traverser = new NodeTraverser(); |
|
37 | 21 | foreach ($this->visitors as $v) { |
|
38 | 21 | $v->init($collection, $file); |
|
|
|||
39 | 21 | $traverser->addVisitor($v); |
|
40 | } |
||
41 | |||
42 | try { |
||
43 | 21 | $tokens = $parser->parse($file->getContents()); |
|
44 | 21 | $traverser->traverse($tokens); |
|
45 | } catch (Error $e) { |
||
46 | trigger_error(sprintf('Skipping file "%s" because of parse Error: %s. ', $path, $e->getMessage())); |
||
47 | } |
||
48 | 21 | } |
|
49 | |||
50 | 1 | public function getType() |
|
51 | { |
||
52 | 1 | return 'php'; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param NodeVisitor $visitor |
||
57 | */ |
||
58 | 21 | public function addVisitor(NodeVisitor $visitor) |
|
62 | } |
||
63 |
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: