Skip to content

Commit

Permalink
upgrade nikic/php-parser to 5 version
Browse files Browse the repository at this point in the history
  • Loading branch information
bpteam committed Jul 18, 2024
1 parent 0311fff commit 53948f8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion src/Generator/Code/Foundation/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use PhpParser\NodeTraverser;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use PhpParser\PhpVersion;

class CodeGenerator implements CodeGeneratorInterface
{
Expand All @@ -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;
Expand Down

0 comments on commit 53948f8

Please sign in to comment.