1 | <?php |
||
26 | abstract class BaseVisitor implements Visitor |
||
27 | { |
||
28 | /** |
||
29 | * @var SourceCollection |
||
30 | */ |
||
31 | protected $collection; |
||
32 | |||
33 | /** |
||
34 | * @var SplFileInfo |
||
35 | */ |
||
36 | protected $file; |
||
37 | |||
38 | /** |
||
39 | * @var DocParser |
||
40 | */ |
||
41 | private $docParser; |
||
42 | |||
43 | 22 | public function init(SourceCollection $collection, SplFileInfo $file) |
|
48 | |||
49 | 20 | protected function getAbsoluteFilePath() |
|
53 | |||
54 | /** |
||
55 | * @param Node $node |
||
56 | * @param string $errorMessage |
||
57 | */ |
||
58 | 7 | protected function addError(Node $node, $errorMessage) |
|
59 | { |
||
60 | 7 | $docComment = $node->getDocComment(); |
|
61 | 7 | $file = $this->getAbsoluteFilePath(); |
|
62 | |||
63 | 7 | if (property_exists($node, 'value')) { |
|
64 | 5 | $line = $node->value->getAttribute('startLine'); |
|
|
|||
65 | 5 | } else { |
|
66 | 2 | $line = $node->getAttribute('startLine'); |
|
67 | } |
||
68 | 7 | if (null !== $docComment) { |
|
69 | 3 | $context = 'file '.$file.' near line '.$line; |
|
70 | 3 | foreach ($this->getDocParser()->parse($docComment->getText(), $context) as $annotation) { |
|
71 | 3 | if ($annotation instanceof Ignore) { |
|
72 | 3 | return; |
|
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | 7 | $this->collection->addError(new Error($errorMessage, $file, $line)); |
|
78 | 7 | } |
|
79 | |||
80 | /** |
||
81 | * @return DocParser |
||
82 | */ |
||
83 | 3 | private function getDocParser() |
|
96 | |||
97 | /** |
||
98 | * @param DocParser $docParser |
||
99 | */ |
||
100 | public function setDocParser(DocParser $docParser) |
||
104 | } |
||
105 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: