66
77use InvalidArgumentException ;
88use Override ;
9- use Stringable ;
109
11- final readonly class FullyQualified implements Stringable
10+ final readonly class FullyQualified implements Importable
1211{
1312 public ClassName $ className ;
1413 public ?NamespaceName $ namespace ;
1514
1615 public function __construct (
17- string $ part ,
18- string ...$ parts ,
16+ Importable | string $ part ,
17+ Importable | string ...$ parts ,
1918 ) {
2019 $ flattened = array_filter (
21- explode ('\\' , implode ('\\' , [$ part , ...$ parts ])),
20+ explode (
21+ '\\' ,
22+ implode (
23+ '\\' ,
24+ array_map (strval (...), [$ part , ...$ parts ]),
25+ ),
26+ ),
2227 fn ($ p ) => $ p !== '' ,
2328 );
2429
@@ -29,15 +34,13 @@ public function __construct(
2934 $ classNamePart = array_pop ($ flattened );
3035 $ this ->className = new ClassName ($ classNamePart );
3136
32- $ this ->namespace = $ flattened !== []
33- ? new NamespaceName (implode ('\\' , $ flattened ))
34- : null ;
37+ $ this ->namespace = $ flattened !== [] ? new NamespaceName (implode ('\\' , $ flattened )) : null ;
3538 }
3639
3740 /**
3841 * @phpstan-return ($input is null ? null : self)
3942 */
40- public static function maybeFromString (null | self | string $ input ) : ?self
43+ public static function maybeFromString (null | Importable | self | string $ input ) : ?self
4144 {
4245 if ($ input === null ) {
4346 return null ;
@@ -47,7 +50,7 @@ public static function maybeFromString(null | self | string $input) : ?self
4750 return $ input ;
4851 }
4952
50- return new self ($ input );
53+ return new self (( string ) $ input );
5154 }
5255
5356 #[Override]
@@ -60,11 +63,13 @@ public function __toString() : string
6063 return $ this ->namespace . '\\' . $ this ->className ;
6164 }
6265
66+ #[Override]
6367 public function equals (object $ other ) : bool
6468 {
6569 return $ other instanceof self && (string ) $ this === (string ) $ other ;
6670 }
6771
72+ #[Override]
6873 public function compare (object $ other ) : int
6974 {
7075 $ thisStr = str_replace ('\\' , ' ' , (string ) $ this );
0 commit comments