-
-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
29 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ final class Types | |
* | ||
* @return Type&NamedType | ||
*/ | ||
public static function byTypeName(string $typeName): Type | ||
public static function load(string $typeName): Type | ||
{ | ||
if (isset(self::$types[$typeName])) { | ||
return self::$types[$typeName]; | ||
|
@@ -59,16 +59,6 @@ public static function byTypeName(string $typeName): Type | |
return self::$types[$typeName] = $type; | ||
} | ||
|
||
/** | ||
* @param class-string<Type&NamedType> $classname | ||
* | ||
* @return \Closure(): Type | ||
*/ | ||
private static function get(string $classname): \Closure | ||
{ | ||
return static fn () => self::byClassName($classname); | ||
} | ||
|
||
/** @param class-string<Type&NamedType> $className */ | ||
private static function byClassName(string $className): Type | ||
{ | ||
|
@@ -83,6 +73,16 @@ private static function byClassName(string $className): Type | |
return self::$types[$typeName] ??= new $className(); | ||
} | ||
|
||
/** | ||
* @param class-string<Type&NamedType> $classname | ||
* | ||
* @return \Closure(): Type&NamedType | ||
*/ | ||
private static function lazyByClassName(string $classname): \Closure | ||
Check failure on line 81 in examples/01-blog/Blog/Types.php GitHub Actions / Static Analysis with PHPStan (7.4)
Check failure on line 81 in examples/01-blog/Blog/Types.php GitHub Actions / Static Analysis with PHPStan (8)
Check failure on line 81 in examples/01-blog/Blog/Types.php GitHub Actions / Static Analysis with PHPStan (8.1)
Check failure on line 81 in examples/01-blog/Blog/Types.php GitHub Actions / Static Analysis with PHPStan (8.2)
|
||
{ | ||
return static fn () => self::byClassName($classname); | ||
} | ||
|
||
/** @throws InvariantViolation */ | ||
public static function boolean(): ScalarType | ||
{ | ||
|
@@ -115,56 +115,56 @@ public static function string(): ScalarType | |
|
||
public static function user(): callable | ||
{ | ||
return self::get(UserType::class); | ||
return self::lazyByClassName(UserType::class); | ||
} | ||
|
||
public static function story(): callable | ||
{ | ||
return self::get(StoryType::class); | ||
return self::lazyByClassName(StoryType::class); | ||
} | ||
|
||
public static function comment(): callable | ||
{ | ||
return self::get(CommentType::class); | ||
return self::lazyByClassName(CommentType::class); | ||
} | ||
|
||
public static function image(): callable | ||
{ | ||
return self::get(ImageType::class); | ||
return self::lazyByClassName(ImageType::class); | ||
} | ||
|
||
public static function node(): callable | ||
{ | ||
return self::get(NodeType::class); | ||
return self::lazyByClassName(NodeType::class); | ||
} | ||
|
||
public static function mention(): callable | ||
{ | ||
return self::get(SearchResultType::class); | ||
return self::lazyByClassName(SearchResultType::class); | ||
} | ||
|
||
public static function imageSize(): callable | ||
{ | ||
return self::get(ImageSizeType::class); | ||
return self::lazyByClassName(ImageSizeType::class); | ||
} | ||
|
||
public static function contentFormat(): callable | ||
{ | ||
return self::get(ContentFormatType::class); | ||
return self::lazyByClassName(ContentFormatType::class); | ||
} | ||
|
||
public static function storyAffordances(): callable | ||
{ | ||
return self::get(StoryAffordancesType::class); | ||
return self::lazyByClassName(StoryAffordancesType::class); | ||
} | ||
|
||
public static function email(): callable | ||
{ | ||
return self::get(EmailType::class); | ||
return self::lazyByClassName(EmailType::class); | ||
} | ||
|
||
public static function url(): callable | ||
{ | ||
return self::get(UrlType::class); | ||
return self::lazyByClassName(UrlType::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters