| Conditions | 2 |
| Paths | 2 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 31 | public function testParseAndDump($code, $expectedDump) |
||
| 32 | { |
||
| 33 | $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new \PhpParser\Lexer\Emulative( |
||
| 34 | array( |
||
| 35 | 'usedAttributes' => array( |
||
| 36 | 'comments', |
||
| 37 | 'startLine', |
||
| 38 | 'endLine', |
||
| 39 | 'startTokenPos', |
||
| 40 | 'endTokenPos' |
||
| 41 | ) |
||
| 42 | ) |
||
| 43 | )); |
||
| 44 | $ast = $parser->parse($code); |
||
| 45 | |||
| 46 | $expressionCompiler = $this->getContext()->getExpressionCompiler(); |
||
| 47 | |||
| 48 | foreach ($ast as $node) { |
||
|
|
|||
| 49 | $compiledExpression = $expressionCompiler ->compile($node); |
||
| 50 | self::assertInstanceOfCompiledExpression($compiledExpression); |
||
| 51 | } |
||
| 52 | |||
| 53 | self::assertSame( |
||
| 54 | json_encode($compiledExpression->__debugInfo()), |
||
| 55 | trim($expectedDump) |
||
| 56 | ); |
||
| 57 | } |
||
| 58 | } |
||
| 59 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.