Skip to content

Commit 243df13

Browse files
committed
use parser v5 for consistent Emulative constructor
1 parent 2b80d6b commit 243df13

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

.github/workflows/ci-linux.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ jobs:
8686

8787
- name: Install PHPUnit
8888
run: |
89-
if [[ ${{ matrix.dependency_versions == 'lowest' }} ]]; then
90-
echo "SYMFONY_PHPUNIT_REQUIRE=nikic/php-parser:^4.18" >> $GITHUB_ENV
91-
fi
9289
vendor/bin/simple-phpunit install
9390
9491
- name: PHPUnit version

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"require": {
1616
"php": ">=8.1",
1717
"doctrine/inflector": "^2.0",
18-
"nikic/php-parser": "^4.18|^5.0",
18+
"nikic/php-parser": "^5.0",
1919
"symfony/config": "^6.4|^7.0",
2020
"symfony/console": "^6.4|^7.0",
2121
"symfony/dependency-injection": "^6.4|^7.0",

src/Util/ClassSourceManipulator.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,14 @@ 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+
'usedAttributes' => [
71+
'comments',
72+
'startLine', 'endLine',
73+
'startTokenPos', 'endTokenPos',
74+
],
75+
]);
76+
$this->parser = new Parser\Php7($this->lexer);
8477

8578
$this->printer = new PrettyPrinter();
8679

@@ -963,10 +956,7 @@ private function setSourceCode(string $sourceCode): void
963956
$this->sourceCode = $sourceCode;
964957
$this->oldStmts = $this->parser->parse($sourceCode);
965958

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(...))) {
959+
if (\is_callable($this->lexer->getTokens(...))) {
970960
$this->oldTokens = $this->lexer->getTokens();
971961
}
972962

0 commit comments

Comments
 (0)