Skip to content

Commit

Permalink
Add Type::lookupName() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Aug 15, 2023
1 parent b30518d commit 3c0f0a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Types/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ public static function getType($name)
return self::getTypeRegistry()->get($name);
}

/**
* Finds a name for the given type.
*
* @throws Exception
*/
public function lookupName(self $type): string
{
return self::getTypeRegistry()->lookupName($type);
}

/**
* Adds a custom type to the type map.
*
Expand Down
7 changes: 7 additions & 0 deletions tests/Types/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ public function testDefaultTypesAreRegistered(string $name): void
self::assertTrue(Type::hasType($name));
}

/** @dataProvider defaultTypesProvider() */
public function testDefaultTypesReverseLookup(string $name): void
{
$type = Type::getType($name);
self::assertSame($name, Type::lookupName($type));
}

/** @return iterable<string[]> */
public static function defaultTypesProvider(): iterable
{
Expand Down

0 comments on commit 3c0f0a6

Please sign in to comment.