Skip to content

Commit f7ee43d

Browse files
committed
feature #1682 use parser v5 for consistent Emulative constructor (weaverryan)
This PR was squashed before being merged into the 1.x branch. Discussion ---------- use parser v5 for consistent Emulative constructor Fixes #1680 No good reason to keep this flexibility Commits ------- 37b028b use parser v5 for consistent Emulative constructor
2 parents 21f7699 + 37b028b commit f7ee43d

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

.github/workflows/ci-linux.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ jobs:
8484

8585
- name: Install PHPUnit
8686
run: |
87-
if [[ ${{ matrix.dependency_versions == 'lowest' }} ]]; then
88-
echo "SYMFONY_PHPUNIT_REQUIRE=nikic/php-parser:^4.18" >> $GITHUB_ENV
89-
fi
9087
vendor/bin/simple-phpunit install
9188
9289
- name: PHPUnit version

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"require": {
1717
"php": ">=8.1",
1818
"doctrine/inflector": "^2.0",
19-
"nikic/php-parser": "^4.18|^5.0",
19+
"nikic/php-parser": "^5.0",
2020
"symfony/config": "^6.4|^7.0",
2121
"symfony/console": "^6.4|^7.0",
2222
"symfony/dependency-injection": "^6.4|^7.0",

src/Util/ClassSourceManipulator.php

+5-21
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,10 @@ public function __construct(
6666
private bool $overwrite = false,
6767
private bool $useAttributesForDoctrineMapping = true,
6868
) {
69-
/* @legacy Support for nikic/php-parser v4 */
70-
if (class_exists(PhpVersion::class)) {
71-
$version = PhpVersion::fromString(\PHP_VERSION);
72-
$this->lexer = new Lexer\Emulative($version);
73-
$this->parser = new Parser\Php8($this->lexer, $version);
74-
} else {
75-
$this->lexer = new Lexer\Emulative([
76-
'usedAttributes' => [
77-
'comments',
78-
'startLine', 'endLine',
79-
'startTokenPos', 'endTokenPos',
80-
],
81-
]);
82-
$this->parser = new Parser\Php7($this->lexer);
83-
}
69+
$this->lexer = new Lexer\Emulative(
70+
PhpVersion::fromString('8.1'),
71+
);
72+
$this->parser = new Parser\Php7($this->lexer);
8473

8574
$this->printer = new PrettyPrinter();
8675

@@ -963,12 +952,7 @@ private function setSourceCode(string $sourceCode): void
963952
$this->sourceCode = $sourceCode;
964953
$this->oldStmts = $this->parser->parse($sourceCode);
965954

966-
/* @legacy Support for nikic/php-parser v4 */
967-
if (\is_callable([$this->parser, 'getTokens'])) {
968-
$this->oldTokens = $this->parser->getTokens();
969-
} elseif (\is_callable($this->lexer->getTokens(...))) {
970-
$this->oldTokens = $this->lexer->getTokens();
971-
}
955+
$this->oldTokens = $this->parser->getTokens();
972956

973957
$traverser = new NodeTraverser();
974958
$traverser->addVisitor(new NodeVisitor\CloningVisitor());

0 commit comments

Comments
 (0)