diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a78e23..0cd18f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,26 @@ jobs: run: composer install -n --prefer-dist - name: Run PHPUnit run: php ./vendor/bin/phpunit + php-test-7_4-with-parser-4: + name: phpunit 7.4 + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: composer:v2 + coverage: xdebug2 + - name: Validate composer.json + run: composer validate --strict + - name: Run composer install + run: composer install -n --prefer-dist + - name: Run downgrade nikic/php-parser + run: composer require nikic/php-parser "^4.12" + - name: Run PHPUnit + run: php ./vendor/bin/phpunit php-test-8_0: name: phpunit 8.0 runs-on: 'ubuntu-latest' diff --git a/composer.json b/composer.json index 44cfaa7..cdb9ff8 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "require": { "php": "^7.4 | ^8.0", "webonyx/graphql-php": "^15.2", - "nikic/php-parser": "^4.12" + "nikic/php-parser": "^4.12 | ^5" }, "require-dev": { "psr/container": "^1 | ^2", diff --git a/src/Generator/Code/Foundation/CodeGenerator.php b/src/Generator/Code/Foundation/CodeGenerator.php index afc36a9..c8de0f1 100644 --- a/src/Generator/Code/Foundation/CodeGenerator.php +++ b/src/Generator/Code/Foundation/CodeGenerator.php @@ -29,6 +29,7 @@ use PhpParser\NodeTraverser; use PhpParser\Parser; use PhpParser\ParserFactory; +use PhpParser\PhpVersion; class CodeGenerator implements CodeGeneratorInterface { @@ -51,7 +52,14 @@ public function __construct( ArgsFieldResolverModelGeneratorInterface $argsFieldResolverModelGenerator, ModelGeneratorInterface ...$generators ) { - $this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); + $parserFactory = new ParserFactory(); + // version of nikic/php-parser is v4 + if (method_exists($parserFactory, 'create')) { + $this->parser = $parserFactory->create(ParserFactory::PREFER_PHP7); + } else { + // version of nikic/php-parser is v5 + $this->parser = $parserFactory->createForVersion(PhpVersion::fromComponents(7, 4)); + } $this->generators = $generators; $this->fieldResolversGenerator = $fieldResolversGenerator; $this->scalarResolverGenerator = $scalarResolverGenerator;