Skip to content

Commit 152066d

Browse files
committed
fix
1 parent b700680 commit 152066d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Model/ResolveNameTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ trait ResolveNameTrait
2222
{
2323
private function resolveName(PhpNamespace $namespace, string $name): string
2424
{
25-
return $namespace->resolveName($name);
25+
if (method_exists(PhpNamespace::class, 'resolveName')) { // @phpstan-ignore-line
26+
return $namespace->resolveName($name);
27+
}
28+
29+
return $name;
2630
}
2731
}

src/Printer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ApiPlatform\SchemaGenerator;
1515

16+
use Nette\PhpGenerator\PhpNamespace;
1617
use Nette\PhpGenerator\Printer as NettePrinter;
1718

1819
final class Printer extends NettePrinter
@@ -22,6 +23,10 @@ public function __construct()
2223
parent::__construct();
2324

2425
$this->linesBetweenMethods = 1;
25-
$this->setTypeResolving(false);
26+
// If the type name cannot be resolved with the namespace and its uses (nette/php-generator >= 4),
27+
// disable type resolving to avoid using the root namespace.
28+
if (!method_exists(PhpNamespace::class, 'resolveName')) { // @phpstan-ignore-line
29+
$this->setTypeResolving(false);
30+
}
2631
}
2732
}

0 commit comments

Comments
 (0)