diff --git a/CHANGELOG.md b/CHANGELOG.md index 00020fb..8307645 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [v3.4.0] +- Add PHP-Parser 5 support + ## [v3.3.0] - Test against PHP 8.3 - Add Symfony 7 support diff --git a/composer.json b/composer.json index 037fce1..64c29a8 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,12 @@ "php": "^7.4 || ^8.0", "symfony/console": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/finder": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "nikic/php-parser": "^4.13", + "nikic/php-parser": "^4.18 || ^5.0", "php-parallel-lint/php-console-highlighter": "^1.0", "phpunit/php-timer": "^2.0||^3.0||^4.0||^5.0||^6.0" }, "require-dev": { - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^9.6", "squizlabs/php_codesniffer": "^2.8.1||^3.5" }, "autoload": { diff --git a/src/Container.php b/src/Container.php index df0dd80..7619b37 100644 --- a/src/Container.php +++ b/src/Container.php @@ -10,13 +10,10 @@ use function gettype; use InvalidArgumentException; use function is_object; -use const PHP_VERSION; use Povils\PHPMND\PhpParser\FileParser; -use PhpParser\Lexer; use PhpParser\Parser; use PhpParser\ParserFactory; use function sprintf; -use function version_compare; class Container { @@ -34,14 +31,8 @@ private function __construct(array $values) public static function create(): self { return new self([ - Lexer::class => static function (self $container): Lexer { - // For PHP < 8.0 we want to specify a lexer object. - // Otherwise, the code creates a `Lexer\Emulative()` instance, which by default uses PHP 8 compatibility - // with e.g. longer list of reserved keywords - return version_compare('8.0', PHP_VERSION, '<') ? new Lexer() : new Lexer\Emulative(); - }, Parser::class => static function (self $container): Parser { - return (new ParserFactory())->create(ParserFactory::PREFER_PHP7, $container->getLexer()); + return (new ParserFactory())->createForHostVersion(); }, FileParser::class => static function (self $container): FileParser { return new FileParser($container->getParser()); @@ -59,11 +50,6 @@ private function getParser(): Parser return $this->get(Parser::class); } - private function getLexer(): Lexer - { - return $this->get(Lexer::class); - } - private function offsetSet(string $id, Closure $value): void { $this->keys[$id] = true; diff --git a/tests/DetectorTest.php b/tests/DetectorTest.php index aff5ea4..d3708cf 100644 --- a/tests/DetectorTest.php +++ b/tests/DetectorTest.php @@ -46,7 +46,7 @@ protected function setUp(): void $this->hintList = new HintList(); $this->detector = new Detector( - new FileParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7)), + new FileParser((new ParserFactory())->createForHostVersion()), $this->option, $this->hintList ); diff --git a/tests/PhpParser/FileParserTest.php b/tests/PhpParser/FileParserTest.php index a73ea5e..0ade31f 100644 --- a/tests/PhpParser/FileParserTest.php +++ b/tests/PhpParser/FileParserTest.php @@ -45,7 +45,7 @@ public function testItParsesTheGivenFileOnlyOnce(): void */ public function testItCanParseFile(SplFileInfo $fileInfo, string $expectedPrintedParsedContents): void { - $statements = (new FileParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7)))->parse($fileInfo); + $statements = (new FileParser((new ParserFactory())->createForHostVersion()))->parse($fileInfo); foreach ($statements as $statement) { $this->assertInstanceOf(Node::class, $statement); @@ -61,7 +61,7 @@ public function testItCanParseFile(SplFileInfo $fileInfo, string $expectedPrinte public function testItThrowsUponFailure(): void { - $parser = new FileParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7)); + $parser = new FileParser((new ParserFactory())->createForHostVersion()); try { $parser->parse(self::createFileInfo('/unknown', 'create(ParserFactory::PREFER_PHP7)->parse($code); + return (array) (new ParserFactory())->createForHostVersion()->parse($code); } /**