1 | <?php |
||
21 | class InlineParserEngine |
||
22 | { |
||
23 | protected $environment; |
||
24 | |||
25 | 1950 | public function __construct(EnvironmentInterface $environment) |
|
29 | |||
30 | /** |
||
31 | * @param Node $container |
||
32 | * @param ReferenceMap $referenceMap |
||
33 | */ |
||
34 | 1662 | public function parse(Node $container, ReferenceMap $referenceMap) |
|
35 | { |
||
36 | 1662 | $inlineParserContext = new InlineParserContext($container, $referenceMap); |
|
|
|||
37 | 1662 | while (($character = $inlineParserContext->getCursor()->getCharacter()) !== null) { |
|
38 | 1659 | if (!$this->parseCharacter($character, $inlineParserContext)) { |
|
39 | 1542 | $this->addPlainText($character, $container, $inlineParserContext); |
|
40 | } |
||
41 | } |
||
42 | |||
43 | 1662 | $this->processInlines($inlineParserContext); |
|
44 | |||
45 | 1662 | $this->collapseAdjoiningTextElements($inlineParserContext); |
|
46 | 1662 | } |
|
47 | |||
48 | /** |
||
49 | * @param string $character |
||
50 | * @param InlineParserContext $inlineParserContext |
||
51 | * |
||
52 | * @return bool Whether we successfully parsed a character at that position |
||
53 | */ |
||
54 | 1659 | protected function parseCharacter(string $character, InlineParserContext $inlineParserContext): bool |
|
64 | |||
65 | /** |
||
66 | * @param InlineParserContext $inlineParserContext |
||
67 | */ |
||
68 | 1662 | protected function processInlines(InlineParserContext $inlineParserContext) |
|
79 | |||
80 | /** |
||
81 | * @param string $character |
||
82 | * @param Node $container |
||
83 | * @param InlineParserContext $inlineParserContext |
||
84 | */ |
||
85 | 1542 | private function addPlainText(string $character, Node $container, InlineParserContext $inlineParserContext) |
|
103 | |||
104 | 1662 | private function collapseAdjoiningTextElements(InlineParserContext $context) |
|
120 | } |
||
121 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.