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 b1e609e
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 static 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 b1e609e

Please sign in to comment.