Skip to content

Commit 37ea1a9

Browse files
authored
Merge pull request #80 from smeghead/feat-79-update-php-parser-version
Update php parser version to v5
2 parents f3b422a + 84dad1e commit 37ea1a9

File tree

8 files changed

+58
-53
lines changed

8 files changed

+58
-53
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
],
99
"require": {
1010
"php" : ">=8.0",
11-
"symfony/finder": "^5.3|^6.0",
12-
"nikic/php-parser": "^4.13",
13-
"phpstan/phpdoc-parser": "^1.23"
11+
"symfony/finder": "^5.3|^6.0|^7.0",
12+
"nikic/php-parser": "^5.1",
13+
"phpstan/phpdoc-parser": "^1.30"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "^9.5",
16+
"phpunit/phpunit": "^9.6",
1717
"clue/phar-composer": "^1.2",
1818
"phpstan/phpstan": "^1.10",
1919
"smeghead/php-vendor-credits": "~0.0.4"

docs/images/dogfood-package.png

2 Bytes
Loading

docs/images/dogfood.svg

Lines changed: 1 addition & 1 deletion
Loading

src/Php/PhpClass.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getNamespace(): array
5252
{
5353
foreach ($this->full as $stmt) {
5454
if ($stmt instanceof Namespace_) {
55-
return $stmt->name->parts;
55+
return $stmt->name->getParts();
5656
}
5757
}
5858
return [];
@@ -84,7 +84,7 @@ public function getClassType(): PhpType
8484
$namespace = [];
8585
foreach ($this->full as $stmt) {
8686
if ($stmt instanceof Namespace_) {
87-
$namespace = $stmt->name->parts;
87+
$namespace = $stmt->name->getParts();
8888
break;
8989
}
9090
}
@@ -134,15 +134,15 @@ private function getUsesRec($stmts, array $uses = []): array
134134
{
135135
foreach ($stmts as $stmt) {
136136
if ($stmt instanceof GroupUse) {
137-
$prefix = $stmt->prefix->parts;
137+
$prefix = $stmt->prefix->getParts();
138138
foreach ($stmt->uses as $u) {
139-
$parts = $u->name->parts;
139+
$parts = $u->name->getParts();
140140
$name = array_pop($parts);
141141
$uses[] = new PhpType(array_merge($prefix, $parts), '', $name, $u->alias);
142142
}
143143
} else if ($stmt instanceof Use_) {
144144
foreach ($stmt->uses as $u) {
145-
$parts = $u->name->parts;
145+
$parts = $u->name->getParts();
146146
$name = array_pop($parts);
147147
$uses[] = new PhpType($parts, '', $name, $u->alias);
148148
}
@@ -179,21 +179,23 @@ public function getExtends(): array
179179
if (property_exists($this->syntax, 'extends')) {
180180
$extend = $this->syntax->{'extends'};
181181
if ($extend instanceof FullyQualified) {
182+
$parts = $extend->getParts();
182183
$extends[] = new PhpType(
183-
array_slice($extend->parts, 0, count($extend->parts) - 1),
184+
array_slice($parts, 0, count($parts) - 1),
184185
'',
185-
(string)end($extend->parts)
186+
(string)end($parts)
186187
);
187188
}
188189
}
189190

190191
if (property_exists($this->syntax, 'implements')) {
191192
foreach ($this->syntax->{'implements'} as $implement) {
192193
if ($implement instanceof FullyQualified) {
194+
$parts = $implement->getParts();
193195
$extends[] = new PhpType(
194-
array_slice($implement->parts, 0, count($implement->parts) - 1),
196+
array_slice($parts, 0, count($parts) - 1),
195197
'',
196-
(string)end($implement->parts)
198+
(string)end($parts)
197199
);
198200
}
199201
}
@@ -231,9 +233,12 @@ public function getUsingTypes(): array
231233
{
232234
$finder = new FindUsePhpTypes($this->syntax);
233235
return array_map(
234-
fn(FullyQualified $x) => new PhpType(
235-
array_slice($x->parts, 0, count($x->parts) - 1), '', (string)end($x->parts)
236-
),
236+
function(FullyQualified $x) {
237+
$parts = $x->getParts();
238+
return new PhpType(
239+
array_slice($parts, 0, count($parts) - 1), '', (string)end($parts)
240+
);
241+
},
237242
$finder->collectTypes()
238243
);
239244
}

src/Php/PhpReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function parseFile(string $directory, string $filename, Options $o
3333
{
3434
$code = (string)file_get_contents($filename);
3535

36-
$parser = (new ParserFactory)->createForHostVersion();
36+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
3737
try {
3838
$ast = $parser->parse($code);
3939
$nameResolver = new NameResolver();

src/Php/PhpTypeExpression.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ private function parseType(Property|Identifier|NullableType|Name|UnionType|Inter
179179
if ($type instanceof Identifier) {
180180
$parts[] = $type->name;
181181
} else if ($type instanceof FullyQualified) {
182-
$parts = $type->parts;
182+
$parts = $type->getParts();
183183
} else if ($type instanceof Name) {
184-
$typeParts = $type->parts;
184+
$typeParts = $type->getParts();
185185
// usesを検索して適切なnamespaceを探す必要がある。
186186
$targets = array_values(array_filter($this->uses, function (PhpType $t) use ($typeParts) {
187187
$name = end($typeParts);
@@ -190,7 +190,7 @@ private function parseType(Property|Identifier|NullableType|Name|UnionType|Inter
190190
if (count($targets) > 0) {
191191
$parts = array_merge($targets[0]->getNamespace(), [end($typeParts)]);
192192
} else {
193-
$parts = array_merge($currentNamespace, $type->parts);
193+
$parts = array_merge($currentNamespace, $type->getParts());
194194
}
195195
}
196196
}

test/PhpDocCommentTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function tearDown(): void
3030

3131
public function testDocString(): void
3232
{
33-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
33+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
3434
$filename = sprintf('%s/enum/TestEnum.php', $this->fixtureDir);
3535
try {
3636
$ast = $parser->parse(file_get_contents($filename));
@@ -48,7 +48,7 @@ public function testDocString(): void
4848
}
4949
public function test_enum_getDescription(): void
5050
{
51-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
51+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
5252
$filename = sprintf('%s/enum/TestEnum.php', $this->fixtureDir);
5353
try {
5454
$ast = $parser->parse(file_get_contents($filename));
@@ -66,7 +66,7 @@ public function test_enum_getDescription(): void
6666

6767
public function testDocStringMultiLines(): void
6868
{
69-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
69+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
7070
$filename = sprintf('%s/enum/TestEnum.php', $this->fixtureDir);
7171
try {
7272
$ast = $parser->parse(file_get_contents($filename));
@@ -87,7 +87,7 @@ public function testDocStringMultiLines(): void
8787

8888
public function test_getDescription(): void
8989
{
90-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
90+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
9191
$filename = sprintf('%s/enum/TestEnum.php', $this->fixtureDir);
9292
try {
9393
$ast = $parser->parse(file_get_contents($filename));
@@ -109,7 +109,7 @@ public function test_getDescription(): void
109109

110110
public function test_getVarType(): void
111111
{
112-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
112+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
113113
$filename = sprintf('%s/phpdoc/product/Product.php', $this->fixtureDir);
114114
try {
115115
$ast = $parser->parse(file_get_contents($filename));
@@ -127,7 +127,7 @@ public function test_getVarType(): void
127127
}
128128
public function test_getParamType(): void
129129
{
130-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
130+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
131131
$filename = sprintf('%s/php8/product/Product.php', $this->fixtureDir);
132132
try {
133133
$ast = $parser->parse(file_get_contents($filename));
@@ -144,7 +144,7 @@ public function test_getParamType(): void
144144
}
145145
public function test_getReturnType(): void
146146
{
147-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
147+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
148148
$filename = sprintf('%s/php8/product/Product.php', $this->fixtureDir);
149149
try {
150150
$ast = $parser->parse(file_get_contents($filename));
@@ -162,7 +162,7 @@ public function test_getReturnType(): void
162162
}
163163
public function test_getVarType_array_expression(): void
164164
{
165-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
165+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
166166
$filename = sprintf('%s/array-expression-in-doc/product/Product.php', $this->fixtureDir);
167167
try {
168168
$ast = $parser->parse(file_get_contents($filename));
@@ -180,7 +180,7 @@ public function test_getVarType_array_expression(): void
180180
}
181181
public function test_getReturnType_array_expression(): void
182182
{
183-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
183+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
184184
$filename = sprintf('%s/array-expression-in-doc/product/Product.php', $this->fixtureDir);
185185
try {
186186
$ast = $parser->parse(file_get_contents($filename));
@@ -198,7 +198,7 @@ public function test_getReturnType_array_expression(): void
198198
}
199199
public function test_getClassComment(): void
200200
{
201-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
201+
$parser = (new ParserFactory)->createForNewestSupportedVersion();
202202
$filename = sprintf('%s/php8/product/Product.php', $this->fixtureDir);
203203
try {
204204
$ast = $parser->parse(file_get_contents($filename));

0 commit comments

Comments
 (0)