Skip to content

Commit b3f996e

Browse files
Update parser create method for PHP-Parser v5 (#7)
* use createForHostVersion for parser create method was removed in nikic/PHP-Parser v5 * Fall back to legacy method if using legacy version. --------- Co-authored-by: Jesse Leite <jesseleite@gmail.com>
1 parent 006108f commit b3f996e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

bin/tinkeray.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ function generateAst($filename)
99
{
1010
$code = file_get_contents($filename);
1111

12-
$parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7);
12+
// Use `createForHostVersion()`, otherwise fall back to legacy `create()` method which was removed in v5
13+
$parser = method_exists('PhpParser\ParserFactory', 'createForHostVersion')
14+
? (new PhpParser\ParserFactory)->createForHostVersion()
15+
: (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7);
1316

1417
return $parser->parse($code);
1518
}

0 commit comments

Comments
 (0)