Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand Down
3 changes: 2 additions & 1 deletion bin/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
}

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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require": {
"php": ">=7.4",
"composer-plugin-api": "^1.0|^2.0",
"mrsuh/php-parser": "94.18.0",
"mrsuh/php-parser": "95.0.2",
"symfony/console": "^4.0|^5.0|^6.0",
"symfony/filesystem": "^4.0|^5.0|^6.0",
"symfony/finder": "^4.0|^5.0|^6.0"
Expand Down
18 changes: 11 additions & 7 deletions src/Compiler/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Mrsuh\PhpGenerics\Compiler;

use Mrsuh\PhpGenerics\Compiler\ClassFinder\ClassFinderInterface;
use PhpParser\Lexer\Emulative;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\Instanceof_;
Expand All @@ -23,10 +22,9 @@ class Parser
{
public static function parse(string $code): array
{
$lexer = new Emulative();
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $lexer);

return $parser->parse($code);
return (new ParserFactory)
->createForNewestSupportedVersion()
->parse($code);
}

/**
Expand Down Expand Up @@ -114,7 +112,7 @@ public static function setNodeName(Node &$node, string $type): void
if (self::isBuiltinType($type)) {
$node = new Node\Identifier($type);
} else {
$node->parts = explode('\\', $type);
$node->name = $type;
}
break;
case $node instanceof Node\Identifier:
Expand All @@ -128,14 +126,20 @@ public static function setNodeName(Node &$node, string $type): void
public static function isBuiltinType(string $type): bool
{
$builtinTypes = [
'array' => true,
'callable' => true,
'bool' => true,
'int' => true,
'float' => true,
'string' => true,
'iterable' => true,
'void' => true,
'object' => true,
'null' => true,
'false' => true,
'mixed' => true,
'array' => true,
'never' => true,
'true' => true,
];

return isset($builtinTypes[strtolower($type)]);
Expand Down
12 changes: 12 additions & 0 deletions tests/monomorphic/230-builtin-types/input/Command/Usage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Test\Command;

use Test\Generic\Box;
use Test\Entity\Bird;
use Test\Entity\Cat;

class Usage extends Box<array,callable,bool,int,float,string,iterable,void,object,null,false,mixed,never,true,Bird,Cat>
{

}
8 changes: 8 additions & 0 deletions tests/monomorphic/230-builtin-types/input/Entity/Bird.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Test\Entity;

class Bird
{

}
8 changes: 8 additions & 0 deletions tests/monomorphic/230-builtin-types/input/Entity/Cat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Test\Entity;

class Cat
{

}
13 changes: 13 additions & 0 deletions tests/monomorphic/230-builtin-types/input/Generic/Box.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Test\Generic;

use Test\Entity\Bird;
use Test\Entity\Cat;

class Box<A,B,C,D,E,F,G,H,I,G,K,L,M,N,O,P> {

public function test($obj): void {
var_dump(Container<A,B,C,D,E,F,G,H,I,G,K,L,M,N,O,P>::class);
}
}
12 changes: 12 additions & 0 deletions tests/monomorphic/230-builtin-types/input/Generic/Container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Test\Generic;

class Container<A,B,C,D,E,F,G,H,I,G,K,L,M,N,O,P> {

private readonly A|B|C|D|E|F|G|H|I|G|K|L|M|N|O|P $content = null;

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 changes: 10 additions & 0 deletions tests/monomorphic/230-builtin-types/output/Command/Usage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Test\Command;

use Test\Generic\Box;
use Test\Entity\Bird;
use Test\Entity\Cat;
class Usage extends \Test\Generic\BoxForArrayAndCallableAndBoolAndIntAndFloatAndStringAndNullAndVoidAndObjectAndFalseAndMixedAndNeverAndTrueAndTestEntityBirdAndTestEntityCat
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Test\Generic;

use Test\Entity\Bird;
use Test\Entity\Cat;
class BoxForArrayAndCallableAndBoolAndIntAndFloatAndStringAndNullAndVoidAndObjectAndFalseAndMixedAndNeverAndTrueAndTestEntityBirdAndTestEntityCat
{
public function test($obj): void
{
var_dump(\Test\Generic\ContainerForArrayAndCallableAndBoolAndIntAndFloatAndStringAndNullAndVoidAndObjectAndFalseAndMixedAndNeverAndTrueAndTestEntityBirdAndTestEntityCat::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Test\Generic;

class ContainerForArrayAndCallableAndBoolAndIntAndFloatAndStringAndNullAndVoidAndObjectAndFalseAndMixedAndNeverAndTrueAndTestEntityBirdAndTestEntityCat
{
private readonly array|callable|bool|int|float|string|null|void|object|null|false|mixed|never|true|\Test\Entity\Bird|\Test\Entity\Cat $content = null;
public function setContent(array|callable|bool|int|float|string|null|void|object|null|false|mixed|never|true|\Test\Entity\Bird|\Test\Entity\Cat $content): array|callable|bool|int|float|string|null|void|object|null|false|mixed|never|true|\Test\Entity\Bird|\Test\Entity\Cat
{
}
}