Skip to content

Commit

Permalink
Extractor: supports PHP-Parser 5.0 (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoosefap authored Jan 17, 2024
1 parent 19ac08c commit 821a89c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"require-dev": {
"nette/tester": "^2.4",
"nikic/php-parser": "^4.15",
"nikic/php-parser": "^5.0",
"tracy/tracy": "^2.8",
"phpstan/phpstan": "^1.0",
"jetbrains/phpstorm-attributes": "dev-master"
Expand Down
5 changes: 2 additions & 3 deletions src/PhpGenerator/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ private function parseCode(string $code): void
throw new Nette\InvalidStateException('The input string is not a PHP code.');
}

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

$traverser = new PhpParser\NodeTraverser;
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpGenerator/fixtures/extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function comment1()
function comment2()
{
// comment
'bar';
"bar";
}

function comment3()
Expand Down

0 comments on commit 821a89c

Please sign in to comment.