Skip to content

Commit

Permalink
misc: rename GenericAssignerLexer to TypeAliasLexer
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed Dec 7, 2021
1 parent 4f56129 commit 6809416
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use CuyZ\Valinor\Type\Parser\Exception\InvalidType;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\ClassAliasSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\ClassContextSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\GenericAssignerSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\TypeAliasAssignerSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\HandleClassGenericSpecification;
use CuyZ\Valinor\Type\Parser\Factory\TypeParserFactory;
use CuyZ\Valinor\Type\Parser\TypeParser;
Expand Down Expand Up @@ -97,7 +97,7 @@ private function typeFromDocBlock(ClassSignature $signature, ReflectionMethod $r
new ClassContextSpecification($signature->className()),
new ClassAliasSpecification($signature->className()),
new HandleClassGenericSpecification(),
new GenericAssignerSpecification($signature->generics()),
new TypeAliasAssignerSpecification($signature->generics()),
);

return $this->parseType($type, $reflection, $parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use CuyZ\Valinor\Type\Parser\Exception\InvalidType;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\ClassAliasSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\ClassContextSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\GenericAssignerSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\TypeAliasAssignerSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\HandleClassGenericSpecification;
use CuyZ\Valinor\Type\Parser\Factory\TypeParserFactory;
use CuyZ\Valinor\Type\Parser\TypeParser;
Expand Down Expand Up @@ -95,7 +95,7 @@ private function typeFromDocBlock(ClassSignature $signature, ReflectionParameter
new ClassContextSpecification($signature->className()),
new ClassAliasSpecification($signature->className()),
new HandleClassGenericSpecification(),
new GenericAssignerSpecification($signature->generics()),
new TypeAliasAssignerSpecification($signature->generics()),
);

return $this->parseType($type, $reflection, $parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use CuyZ\Valinor\Type\Parser\Exception\InvalidType;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\ClassAliasSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\ClassContextSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\GenericAssignerSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\HandleClassGenericSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\TypeAliasAssignerSpecification;
use CuyZ\Valinor\Type\Parser\Factory\TypeParserFactory;
use CuyZ\Valinor\Type\Parser\TypeParser;
use CuyZ\Valinor\Type\Type;
Expand Down Expand Up @@ -104,7 +104,7 @@ private function typeFromDocBlock(ClassSignature $signature, ReflectionProperty
new ClassContextSpecification($signature->className()),
new ClassAliasSpecification($signature->className()),
new HandleClassGenericSpecification(),
new GenericAssignerSpecification($signature->generics()),
new TypeAliasAssignerSpecification($signature->generics()),
);

return $this->parseType($type, $reflection, $parser);
Expand Down
8 changes: 4 additions & 4 deletions src/Type/Parser/Factory/LexingTypeParserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use CuyZ\Valinor\Type\Parser\CachedParser;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\ClassAliasSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\ClassContextSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\GenericAssignerSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\TypeAliasAssignerSpecification;
use CuyZ\Valinor\Type\Parser\Factory\Specifications\HandleClassGenericSpecification;
use CuyZ\Valinor\Type\Parser\Lexer\ClassAliasLexer;
use CuyZ\Valinor\Type\Parser\Lexer\ClassContextLexer;
use CuyZ\Valinor\Type\Parser\Lexer\ClassGenericLexer;
use CuyZ\Valinor\Type\Parser\Lexer\GenericAssignerLexer;
use CuyZ\Valinor\Type\Parser\Lexer\TypeAliasLexer;
use CuyZ\Valinor\Type\Parser\Lexer\NativeLexer;
use CuyZ\Valinor\Type\Parser\Lexer\TypeLexer;
use CuyZ\Valinor\Type\Parser\LexingParser;
Expand Down Expand Up @@ -62,8 +62,8 @@ private function transform(TypeLexer $lexer, object $specification): TypeLexer
return new ClassGenericLexer($lexer, $this, $this->templateParser);
}

if ($specification instanceof GenericAssignerSpecification) {
return new GenericAssignerLexer($lexer, $specification->generics());
if ($specification instanceof TypeAliasAssignerSpecification) {
return new TypeAliasLexer($lexer, $specification->aliases());
}

throw new LogicException('Unhandled specification of type `' . get_class($specification) . '`.');
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace CuyZ\Valinor\Type\Parser\Factory\Specifications;

use CuyZ\Valinor\Type\Type;

final class TypeAliasAssignerSpecification
{
/** @var array<string, Type> */
private array $aliases;

/**
* @param array<string, Type> $aliases
*/
public function __construct(array $aliases)
{
$this->aliases = $aliases;
}

/**
* @return array<string, Type>
*/
public function aliases(): array
{
return $this->aliases;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
use CuyZ\Valinor\Type\Parser\Lexer\Token\TypeToken;
use CuyZ\Valinor\Type\Type;

final class GenericAssignerLexer implements TypeLexer
final class TypeAliasLexer implements TypeLexer
{
private TypeLexer $delegate;

/** @var array<string, Type> */
private array $generics;
private array $aliases;

/**
* @param array<string, Type> $generics
* @param array<string, Type> $aliases
*/
public function __construct(TypeLexer $delegate, array $generics)
public function __construct(TypeLexer $delegate, array $aliases)
{
$this->delegate = $delegate;
$this->generics = $generics;
$this->aliases = $aliases;
}

public function tokenize(string $symbol): Token
{
if (isset($this->generics[$symbol])) {
return new TypeToken($this->generics[$symbol]);
if (isset($this->aliases[$symbol])) {
return new TypeToken($this->aliases[$symbol]);
}

return $this->delegate->tokenize($symbol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use CuyZ\Valinor\Tests\Fake\Type\FakeType;
use CuyZ\Valinor\Tests\Fake\Type\Parser\Lexer\FakeTypeLexer;
use CuyZ\Valinor\Tests\Fake\Type\Parser\Lexer\Token\FakeToken;
use CuyZ\Valinor\Type\Parser\Lexer\GenericAssignerLexer;
use CuyZ\Valinor\Type\Parser\Lexer\TypeAliasLexer;
use CuyZ\Valinor\Type\Parser\Lexer\Token\TypeToken;
use CuyZ\Valinor\Type\Parser\Lexer\TokenStream;
use PHPUnit\Framework\TestCase;

final class GenericAssignerLexerTest extends TestCase
final class TypeAliasLexerTest extends TestCase
{
private FakeTypeLexer $delegate;

Expand All @@ -30,7 +30,7 @@ public function test_non_generic_symbol_is_handled_by_delegate(): void

$this->delegate->will($symbol, $token);

$lexer = new GenericAssignerLexer($this->delegate, ['TemplateA' => new FakeType()]);
$lexer = new TypeAliasLexer($this->delegate, ['TemplateA' => new FakeType()]);

self::assertSame($token, $lexer->tokenize($symbol));
}
Expand All @@ -39,7 +39,7 @@ public function test_symbol_is_generic_is_returned(): void
{
$type = new FakeType();

$lexer = new GenericAssignerLexer($this->delegate, ['Template' => $type]);
$lexer = new TypeAliasLexer($this->delegate, ['Template' => $type]);

/** @var TypeToken $result */
$result = $lexer->tokenize('Template');
Expand Down

0 comments on commit 6809416

Please sign in to comment.