Skip to content

Commit e0249c1

Browse files
committed
Try alternative alias idea
1 parent 1f873d7 commit e0249c1

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Context.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Typhoon\PHPStanTypeParser;
66

7-
use Typhoon\Type\Alias\AtClass;
8-
use Typhoon\Type\Alias\AtFunction;
7+
use Typhoon\Type\AliasAtClassT;
8+
use Typhoon\Type\AliasAtFunctionT;
99
use Typhoon\Type\TemplateT;
1010

1111
final class Context
@@ -21,7 +21,7 @@ final class Context
2121
private array $templates = [];
2222

2323
/**
24-
* @var array<non-empty-string, AtFunction|AtClass>
24+
* @var array<non-empty-string, AliasAtFunctionT|AliasAtClassT>
2525
*/
2626
private array $aliases = [];
2727

@@ -48,7 +48,7 @@ public function useTemplate(TemplateT $template): self
4848
/**
4949
* @param ?non-empty-string $as
5050
*/
51-
public function useAlias(AtFunction|AtClass $alias, ?string $as = null): self
51+
public function useAlias(AliasAtFunctionT|AliasAtClassT $alias, ?string $as = null): self
5252
{
5353
$context = clone $this;
5454
$context->aliases[$as ?? $alias->name] = $alias;
@@ -61,7 +61,7 @@ public function resolveAsClass(string $name): Name
6161
return Name::parse($name)->resolveClass($this->namespace, $this->importTable);
6262
}
6363

64-
public function resolve(string $name): TemplateT|AtFunction|AtClass|Name
64+
public function resolve(string $name): TemplateT|AliasAtFunctionT|AliasAtClassT|Name
6565
{
6666
return $this->templates[$name] ?? $this->aliases[$name] ?? $this->resolveAsClass($name);
6767
}

src/Parser.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
use PHPStan\PhpDocParser\Parser\TypeParser;
3232
use PHPStan\PhpDocParser\ParserConfig;
3333
use Typhoon\Type;
34-
use Typhoon\Type\Alias\AtClass;
35-
use Typhoon\Type\Alias\AtFunction;
34+
use Typhoon\Type\AliasAtClassT;
35+
use Typhoon\Type\AliasAtFunctionT;
3636
use Typhoon\Type\AliasT;
3737
use Typhoon\Type\ArrayBareT;
3838
use Typhoon\Type\ArrayT;
@@ -280,11 +280,12 @@ private function identifier(string $name, array $genericNodes = []): Type
280280
return $resolved;
281281
}
282282

283-
if ($resolved instanceof AtFunction || $resolved instanceof AtClass) {
284-
return new AliasT(
285-
name: $resolved,
286-
templateArguments: $templateArguments,
287-
);
283+
if ($resolved instanceof AliasAtFunctionT || $resolved instanceof AliasAtClassT) {
284+
if ($templateArguments === []) {
285+
return $resolved;
286+
}
287+
288+
return new AliasT($resolved, $templateArguments);
288289
}
289290

290291
/** @var class-string */

0 commit comments

Comments
 (0)