Skip to content

Commit a6c4bda

Browse files
committed
fix: set PHP parser to specific version 8.2
1 parent 6a46c96 commit a6c4bda

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

example/generate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
use PhpKafka\PhpAvroSchemaGenerator\Parser\ClassPropertyParser;
1212
use PhpKafka\PhpAvroSchemaGenerator\Generator\SchemaGenerator;
1313
use PhpParser\ParserFactory;
14+
use PhpParser\PhpVersion;
1415

15-
$parser = (new ParserFactory())->createForNewestSupportedVersion();
16+
$parser = (new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2));
1617
$classPropertyParser = new ClassPropertyParser(new DocCommentParser());
1718
$classParser = new ClassParser($parser, $classPropertyParser);
1819

src/ServiceProvider/ParserServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PhpKafka\PhpAvroSchemaGenerator\Parser\DocCommentParserInterface;
1313
use PhpParser\ParserFactory;
1414
use PhpParser\Parser;
15+
use PhpParser\PhpVersion;
1516
use Pimple\Container;
1617
use Pimple\ServiceProviderInterface;
1718

@@ -24,7 +25,7 @@ public function register(Container $container): void
2425
};
2526

2627
$container[Parser::class] = static function (Container $container): Parser {
27-
return $container[ParserFactory::class]->createForNewestSupportedVersion();
28+
return $container[ParserFactory::class]->createForVersion(PhpVersion::fromComponents(8,2));
2829
};
2930

3031
$container[DocCommentParserInterface::class] = static function (): DocCommentParserInterface {

tests/Integration/Parser/ClassParserTest.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpKafka\PhpAvroSchemaGenerator\Parser\DocCommentParser;
1010
use PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassPropertyInterface;
1111
use PhpParser\ParserFactory;
12+
use PhpParser\PhpVersion;
1213
use PHPUnit\Framework\TestCase;
1314

1415
/**
@@ -20,7 +21,7 @@ public function testGetClassName(): void
2021
{
2122
$filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php';
2223
$propertyParser = new ClassPropertyParser(new DocCommentParser());
23-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
24+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
2425
$parser->setCode((string) file_get_contents($filePath));
2526
self::assertEquals('SomeTestClass', $parser->getClassName());
2627
self::assertEquals('SomeTestClass', $parser->getClassName());
@@ -30,7 +31,7 @@ public function testGetClassNameForInterface(): void
3031
{
3132
$filePath = __DIR__ . '/../../../example/classes/SomeTestInterface.php';
3233
$propertyParser = new ClassPropertyParser(new DocCommentParser());
33-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
34+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
3435
$parser->setCode((string) file_get_contents($filePath));
3536
self::assertNull($parser->getClassName());
3637
}
@@ -39,7 +40,7 @@ public function testGetNamespace(): void
3940
{
4041
$filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php';
4142
$propertyParser = new ClassPropertyParser(new DocCommentParser());
42-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
43+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
4344
$parser->setCode((string) file_get_contents($filePath));
4445
self::assertEquals('PhpKafka\\PhpAvroSchemaGenerator\\Example', $parser->getNamespace());
4546
self::assertEquals('PhpKafka\\PhpAvroSchemaGenerator\\Example', $parser->getNamespace());
@@ -49,7 +50,7 @@ public function testGetProperties(): void
4950
{
5051
$filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php';
5152
$propertyParser = new ClassPropertyParser(new DocCommentParser());
52-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
53+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
5354
$parser->setCode((string) file_get_contents($filePath));
5455
$properties = $parser->getProperties();
5556
self::assertCount(16, $properties);
@@ -62,7 +63,7 @@ public function testGetProperties(): void
6263
public function testClassAndNamespaceAreNullWithNoCode(): void
6364
{
6465
$propertyParser = new ClassPropertyParser(new DocCommentParser());
65-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
66+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
6667
$refObject = new \ReflectionObject($parser);
6768
$refProperty = $refObject->getProperty('statements');
6869
$refProperty->setAccessible(true);
@@ -76,7 +77,7 @@ public function testClassAndNamespaceAreNullWithNoCode(): void
7677
public function testClassWithNoParent(): void
7778
{
7879
$propertyParser = new ClassPropertyParser(new DocCommentParser());
79-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
80+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
8081
$parser->setCode('<?php class foo {}');
8182
self::assertNull($parser->getNamespace());
8283
self::assertNull($parser->getParentClassName());
@@ -87,7 +88,7 @@ public function testClassWithNoParent(): void
8788
public function testClassWithNullableType(): void
8889
{
8990
$propertyParser = new ClassPropertyParser(new DocCommentParser());
90-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
91+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
9192
$parser->setCode('
9293
<?php
9394
class foo {
@@ -102,7 +103,7 @@ class foo {
102103
public function testClassWithUnionType(): void
103104
{
104105
$propertyParser = new ClassPropertyParser(new DocCommentParser());
105-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
106+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
106107
$parser->setCode('
107108
<?php
108109
class foo {
@@ -117,7 +118,7 @@ class foo {
117118
public function testClassWithDocUnionType(): void
118119
{
119120
$propertyParser = new ClassPropertyParser(new DocCommentParser());
120-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
121+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
121122
$parser->setCode('
122123
<?php
123124
class foo {
@@ -135,7 +136,7 @@ class foo {
135136
public function testClassWithAnnotations(): void
136137
{
137138
$propertyParser = new ClassPropertyParser(new DocCommentParser());
138-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
139+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
139140
$parser->setCode('
140141
<?php
141142
class foo {
@@ -159,7 +160,7 @@ class foo {
159160
public function testClassWithNoParentFile(): void
160161
{
161162
$propertyParser = new ClassPropertyParser(new DocCommentParser());
162-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
163+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
163164
$parser->setCode('<?php class foo extends \RuntimeException {private $x;}');
164165
$properties = $parser->getProperties();
165166
self::assertEquals(1, count($properties));

tests/Integration/Parser/ClassPropertyParserTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpKafka\PhpAvroSchemaGenerator\Parser\ClassPropertyParser;
99
use PhpKafka\PhpAvroSchemaGenerator\Parser\DocCommentParser;
1010
use PhpParser\ParserFactory;
11+
use PhpParser\PhpVersion;
1112
use PHPUnit\Framework\TestCase;
1213

1314
/**
@@ -18,7 +19,7 @@ class ClassPropertyParserTest extends TestCase
1819
public function testNullDefaultProperty(): void
1920
{
2021
$propertyParser = new ClassPropertyParser(new DocCommentParser());
21-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
22+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
2223
$parser->setCode('
2324
<?php
2425
class foo {
@@ -36,7 +37,7 @@ class foo {
3637
public function testIntDefaultProperty(): void
3738
{
3839
$propertyParser = new ClassPropertyParser(new DocCommentParser());
39-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
40+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
4041
$parser->setCode('
4142
<?php
4243
class foo {
@@ -54,7 +55,7 @@ class foo {
5455
public function testFloatDefaultProperty(): void
5556
{
5657
$propertyParser = new ClassPropertyParser(new DocCommentParser());
57-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
58+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
5859
$parser->setCode('
5960
<?php
6061
class foo {
@@ -72,7 +73,7 @@ class foo {
7273
public function testEmptyStringDefaultProperty(): void
7374
{
7475
$propertyParser = new ClassPropertyParser(new DocCommentParser());
75-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
76+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
7677
$parser->setCode('
7778
<?php
7879
class foo {

tests/Integration/Registry/ClassRegistryTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PhpKafka\PhpAvroSchemaGenerator\Registry\ClassRegistry;
1414
use PhpKafka\PhpAvroSchemaGenerator\Registry\ClassRegistryInterface;
1515
use PhpParser\ParserFactory;
16+
use PhpParser\PhpVersion;
1617
use PHPUnit\Framework\TestCase;
1718
use ReflectionClass;
1819
use SplFileInfo;
@@ -25,7 +26,7 @@ class ClassRegistryTest extends TestCase
2526
public function testClassDirectory(): void
2627
{
2728
$propertyParser = new ClassPropertyParser(new DocCommentParser());
28-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
29+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
2930
$converter = new PhpClassConverter($parser);
3031
$registry = new ClassRegistry($converter);
3132
$result = $registry->addClassDirectory('/tmp');
@@ -39,7 +40,7 @@ public function testLoad(): void
3940
$classDir = __DIR__ . '/../../../example/classes';
4041

4142
$propertyParser = new ClassPropertyParser(new DocCommentParser());
42-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
43+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
4344
$converter = new PhpClassConverter($parser);
4445
$registry = (new ClassRegistry($converter))->addClassDirectory($classDir)->load();
4546

@@ -58,7 +59,7 @@ public function testRegisterSchemaFileThatDoesntExist(): void
5859
{
5960
$fileInfo = new SplFileInfo('somenonexistingfile');
6061
$propertyParser = new ClassPropertyParser(new DocCommentParser());
61-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
62+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
6263
$converter = new PhpClassConverter($parser);
6364
$registry = new ClassRegistry($converter);
6465

@@ -80,7 +81,7 @@ public function testRegisterSchemaFileThatIsNotReadable(): void
8081
$fileInfo = new SplFileInfo($filePath);
8182

8283
$propertyParser = new ClassPropertyParser(new DocCommentParser());
83-
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
84+
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
8485
$converter = new PhpClassConverter($parser);
8586
$registry = new ClassRegistry($converter);
8687

0 commit comments

Comments
 (0)