Skip to content

Commit 9afd157

Browse files
authored
Merge pull request #13 from mrsuh/php-parser
nikic/PHP-Parser v5.0.2
2 parents e82e25a + 5ab38b3 commit 9afd157

12 files changed

+102
-10
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
steps:
2424
- name: "Checkout"
25-
uses: "actions/checkout@v2"
25+
uses: "actions/checkout@v4"
2626

2727
- name: "Install PHP"
2828
uses: "shivammathur/setup-php@v2"

bin/test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
}
7171

7272
if ($outputFiles->count() !== count($result->getConcreteClasses())) {
73-
$success = false;
73+
$allTestsSuccess = false;
74+
printf("%s - [skip failed]\n", $directory->getBasename());
7475
continue;
7576
}
7677

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"require": {
2626
"php": ">=7.4",
2727
"composer-plugin-api": "^1.0|^2.0",
28-
"mrsuh/php-parser": "94.18.0",
28+
"mrsuh/php-parser": "95.0.2",
2929
"symfony/console": "^4.0|^5.0|^6.0",
3030
"symfony/filesystem": "^4.0|^5.0|^6.0",
3131
"symfony/finder": "^4.0|^5.0|^6.0"

src/Compiler/Parser.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Mrsuh\PhpGenerics\Compiler;
44

55
use Mrsuh\PhpGenerics\Compiler\ClassFinder\ClassFinderInterface;
6-
use PhpParser\Lexer\Emulative;
76
use PhpParser\Node;
87
use PhpParser\Node\Expr\ClassConstFetch;
98
use PhpParser\Node\Expr\Instanceof_;
@@ -23,10 +22,9 @@ class Parser
2322
{
2423
public static function parse(string $code): array
2524
{
26-
$lexer = new Emulative();
27-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $lexer);
28-
29-
return $parser->parse($code);
25+
return (new ParserFactory)
26+
->createForNewestSupportedVersion()
27+
->parse($code);
3028
}
3129

3230
/**
@@ -114,7 +112,7 @@ public static function setNodeName(Node &$node, string $type): void
114112
if (self::isBuiltinType($type)) {
115113
$node = new Node\Identifier($type);
116114
} else {
117-
$node->parts = explode('\\', $type);
115+
$node->name = $type;
118116
}
119117
break;
120118
case $node instanceof Node\Identifier:
@@ -128,14 +126,20 @@ public static function setNodeName(Node &$node, string $type): void
128126
public static function isBuiltinType(string $type): bool
129127
{
130128
$builtinTypes = [
129+
'array' => true,
130+
'callable' => true,
131131
'bool' => true,
132132
'int' => true,
133133
'float' => true,
134134
'string' => true,
135135
'iterable' => true,
136+
'void' => true,
136137
'object' => true,
138+
'null' => true,
139+
'false' => true,
137140
'mixed' => true,
138-
'array' => true,
141+
'never' => true,
142+
'true' => true,
139143
];
140144

141145
return isset($builtinTypes[strtolower($type)]);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Test\Command;
4+
5+
use Test\Generic\Box;
6+
use Test\Entity\Bird;
7+
use Test\Entity\Cat;
8+
9+
class Usage extends Box<array,callable,bool,int,float,string,iterable,void,object,null,false,mixed,never,true,Bird,Cat>
10+
{
11+
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Test\Entity;
4+
5+
class Bird
6+
{
7+
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Test\Entity;
4+
5+
class Cat
6+
{
7+
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Test\Generic;
4+
5+
use Test\Entity\Bird;
6+
use Test\Entity\Cat;
7+
8+
class Box<A,B,C,D,E,F,G,H,I,G,K,L,M,N,O,P> {
9+
10+
public function test($obj): void {
11+
var_dump(Container<A,B,C,D,E,F,G,H,I,G,K,L,M,N,O,P>::class);
12+
}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Test\Generic;
4+
5+
class Container<A,B,C,D,E,F,G,H,I,G,K,L,M,N,O,P> {
6+
7+
private readonly A|B|C|D|E|F|G|H|I|G|K|L|M|N|O|P $content = null;
8+
9+
public function setContent(A|B|C|D|E|F|G|H|I|G|K|L|M|N|O|P $content): A|B|C|D|E|F|G|H|I|G|K|L|M|N|O|P {
10+
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Test\Command;
4+
5+
use Test\Generic\Box;
6+
use Test\Entity\Bird;
7+
use Test\Entity\Cat;
8+
class Usage extends \Test\Generic\BoxForArrayAndCallableAndBoolAndIntAndFloatAndStringAndNullAndVoidAndObjectAndFalseAndMixedAndNeverAndTrueAndTestEntityBirdAndTestEntityCat
9+
{
10+
}

0 commit comments

Comments
 (0)