Skip to content

Commit 821a89c

Browse files
authored
Extractor: supports PHP-Parser 5.0 (#150)
1 parent 19ac08c commit 821a89c

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"require-dev": {
2222
"nette/tester": "^2.4",
23-
"nikic/php-parser": "^4.15",
23+
"nikic/php-parser": "^5.0",
2424
"tracy/tracy": "^2.8",
2525
"phpstan/phpstan": "^1.0",
2626
"jetbrains/phpstorm-attributes": "dev-master"

src/PhpGenerator/Extractor.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ private function parseCode(string $code): void
4646
throw new Nette\InvalidStateException('The input string is not a PHP code.');
4747
}
4848

49-
$this->code = Nette\Utils\Strings::normalizeNewlines($code);
50-
$lexer = new PhpParser\Lexer\Emulative(['usedAttributes' => ['startFilePos', 'endFilePos', 'comments']]);
51-
$parser = (new ParserFactory)->create(ParserFactory::ONLY_PHP7, $lexer);
49+
$this->code = Nette\Utils\Strings::unixNewLines($code);
50+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
5251
$stmts = $parser->parse($this->code);
5352

5453
$traverser = new PhpParser\NodeTraverser;

tests/PhpGenerator/fixtures/extractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function comment1()
1818
function comment2()
1919
{
2020
// comment
21-
'bar';
21+
"bar";
2222
}
2323

2424
function comment3()

0 commit comments

Comments
 (0)