From 25a5f5fa3769f09e392adc6c9a191093da96fe29 Mon Sep 17 00:00:00 2001 From: Matthew King <32152670+matthewpaulking@users.noreply.github.com> Date: Tue, 5 Mar 2024 21:43:48 -0700 Subject: [PATCH 1/2] use createForHostVersion for parser create method was removed in nikic/PHP-Parser v5 --- bin/tinkeray.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/tinkeray.php b/bin/tinkeray.php index dfcbc7f..236edd4 100644 --- a/bin/tinkeray.php +++ b/bin/tinkeray.php @@ -9,7 +9,7 @@ function generateAst($filename) { $code = file_get_contents($filename); - $parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7); + $parser = (new PhpParser\ParserFactory)->createForHostVersion(); return $parser->parse($code); } From 86ca9263f89054576bde44dbedb271c3f529e2db Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Wed, 10 Apr 2024 21:54:48 -0400 Subject: [PATCH 2/2] Fall back to legacy method if using legacy version. --- bin/tinkeray.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/tinkeray.php b/bin/tinkeray.php index 236edd4..aa63101 100644 --- a/bin/tinkeray.php +++ b/bin/tinkeray.php @@ -9,7 +9,10 @@ function generateAst($filename) { $code = file_get_contents($filename); - $parser = (new PhpParser\ParserFactory)->createForHostVersion(); + // Use `createForHostVersion()`, otherwise fall back to legacy `create()` method which was removed in v5 + $parser = method_exists('PhpParser\ParserFactory', 'createForHostVersion') + ? (new PhpParser\ParserFactory)->createForHostVersion() + : (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7); return $parser->parse($code); }