Skip to content

Upgrade to nikic/php-parser:^5.0 #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:
strategy:
matrix:
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
Expand All @@ -39,10 +37,6 @@ jobs:
- name: "Install dependencies"
run: "composer install --no-interaction --no-progress"

- name: "Downgrade PHPUnit"
if: matrix.php-version == '7.2' || matrix.php-version == '7.3'
run: "composer require --dev phpunit/phpunit:^7.5.20 --update-with-dependencies"

- name: "Lint"
run: "make lint"

Expand Down Expand Up @@ -92,8 +86,6 @@ jobs:
matrix:
operating-system: [ubuntu-latest, windows-latest]
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
Expand All @@ -120,10 +112,6 @@ jobs:
if: ${{ matrix.dependencies == 'highest' }}
run: "composer update --no-interaction --no-progress"

- name: "Downgrade PHPUnit"
if: matrix.php-version == '7.2' || matrix.php-version == '7.3'
run: "composer require --dev phpunit/phpunit:^7.5.20 --update-with-dependencies"

- name: "Tests"
run: "make tests"

Expand All @@ -135,8 +123,6 @@ jobs:
fail-fast: false
matrix:
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
Expand All @@ -157,9 +143,5 @@ jobs:
- name: "Install dependencies"
run: "composer update --no-interaction --no-progress"

- name: "Downgrade PHPUnit"
if: matrix.php-version == '7.2' || matrix.php-version == '7.3'
run: "composer require --dev phpunit/phpunit:^7.5.20 --update-with-dependencies"

- name: "PHPStan"
run: "make phpstan"
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"license": "MIT",
"require": {
"php": "^7.2 || ^8.0"
"php": "^7.4 || ^8.0"
},
"require-dev": {
"doctrine/annotations": "^2.0",
"nikic/php-parser": "^4.15",
"nikic/php-parser": "^5.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^1.5",
Expand Down
24 changes: 7 additions & 17 deletions tests/PHPStan/Printer/IntegrationPrinterWithPhpParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace PHPStan\PhpDocParser\Printer;

use PhpParser\Comment\Doc;
use PhpParser\Lexer\Emulative;
use PhpParser\Node as PhpNode;
use PhpParser\NodeTraverser as PhpParserNodeTraverser;
use PhpParser\NodeVisitor\CloningVisitor as PhpParserCloningVisitor;
use PhpParser\NodeVisitorAbstract;
use PhpParser\Parser\Php7;
use PhpParser\ParserFactory;
use PHPStan\PhpDocParser\Ast\AbstractNodeVisitor;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
Expand Down Expand Up @@ -66,14 +65,8 @@ public function enterNode(Node $node)
*/
public function testPrint(string $file, string $expectedFile, NodeVisitor $visitor): void
{
$lexer = new Emulative([
'usedAttributes' => [
'comments',
'startLine', 'endLine',
'startTokenPos', 'endTokenPos',
],
]);
$phpParser = new Php7($lexer);
$phpParser = (new ParserFactory())->createForNewestSupportedVersion();

$phpTraverser = new PhpParserNodeTraverser();
$phpTraverser->addVisitor(new PhpParserCloningVisitor());

Expand All @@ -85,20 +78,18 @@ public function testPrint(string $file, string $expectedFile, NodeVisitor $visit

/** @var PhpNode[] $oldStmts */
$oldStmts = $phpParser->parse($fileContents);
$oldTokens = $lexer->getTokens();
$oldTokens = $phpParser->getTokens();

$phpTraverser2 = new PhpParserNodeTraverser();
$phpTraverser2->addVisitor(new class ($visitor) extends NodeVisitorAbstract {
$phpTraverser->addVisitor(new class ($visitor) extends NodeVisitorAbstract {

/** @var NodeVisitor */
private $visitor;
private NodeVisitor $visitor;

public function __construct(NodeVisitor $visitor)
{
$this->visitor = $visitor;
}

public function enterNode(PhpNode $phpNode)
public function enterNode(PhpNode $phpNode): ?PhpNode
{
if ($phpNode->getDocComment() === null) {
return null;
Expand Down Expand Up @@ -137,7 +128,6 @@ public function enterNode(PhpNode $phpNode)

/** @var PhpNode[] $newStmts */
$newStmts = $phpTraverser->traverse($oldStmts);
$newStmts = $phpTraverser2->traverse($newStmts);

$newCode = $printer->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
$this->assertStringEqualsFile($expectedFile, $newCode);
Expand Down