@@ -9,7 +9,7 @@ final class Identifier extends Node implements \Stringable
99 /**
1010 * @var list<non-empty-string>
1111 */
12- private const SPECIAL_CLASS_NAME = [
12+ private const array SPECIAL_CLASS_NAME = [
1313 'self ' ,
1414 'parent ' ,
1515 'static ' ,
@@ -18,7 +18,7 @@ final class Identifier extends Node implements \Stringable
1818 /**
1919 * @var list<non-empty-string>
2020 */
21- private const BUILTIN_TYPE_NAME = [
21+ private const array BUILTIN_TYPE_NAME = [
2222 'mixed ' ,
2323 'string ' ,
2424 'int ' ,
@@ -35,23 +35,6 @@ final class Identifier extends Node implements \Stringable
3535 'false ' ,
3636 ];
3737
38- /**
39- * @var non-empty-string
40- */
41- public readonly string $ value ;
42-
43- /**
44- * @param non-empty-string $value
45- */
46- public function __construct (string $ value )
47- {
48- $ value = \trim ($ value );
49-
50- assert ($ value !== '' , new \InvalidArgumentException ('Identifier value cannot be empty ' ));
51-
52- $ this ->value = $ value ;
53- }
54-
5538 /**
5639 * Returns {@see true} if the identifier contains the name of
5740 * a "virtual" type, i.e. invalid in the PHP namespace.
@@ -61,41 +44,56 @@ public function __construct(string $value)
6144 * - `non-empty-array` - Virtual, cannot be defined in PHP.
6245 * - `empty-string` - Virtual, cannot be defined in PHP.
6346 */
64- public function isVirtual (): bool
65- {
66- return \str_contains ($ this ->value , '- ' );
47+ public bool $ isVirtual {
48+ get => \str_contains ($ this ->value , '- ' );
6749 }
6850
6951 /**
7052 * Returns {@see true} in case of name contains special class reference.
7153 */
72- public function isSpecial (): bool
73- {
74- return self ::looksLikeSpecial ($ this ->value );
54+ public bool $ isSpecial {
55+ get => self ::isLooksLikeSpecial ($ this ->value );
7556 }
7657
7758 /**
78- * Returns {@see true} in case of passed "$name" argument looks like
79- * a special type name or {@see false} instead.
59+ * Returns {@see true} in case of name contains builtin type name.
8060 */
81- public static function looksLikeSpecial (string $ name ): bool
61+ public bool $ isBuiltin {
62+ get => self ::isLooksLikeBuiltin ($ this ->value );
63+ }
64+
65+ public function __construct (
66+ /**
67+ * @var non-empty-string
68+ */
69+ public readonly string $ value ,
70+ ) {}
71+
72+ public static function createFromString (string |\Stringable $ value ): self
8273 {
83- return \in_array (\strtolower ($ name ), self ::SPECIAL_CLASS_NAME , true );
74+ $ normalized = \trim ((string ) $ value );
75+
76+ if ($ normalized === '' ) {
77+ throw new \InvalidArgumentException ('Name identifier cannot be empty ' );
78+ }
79+
80+ return new self ($ normalized );
8481 }
8582
8683 /**
87- * Returns {@see true} in case of name contains builtin type name.
84+ * Returns {@see true} in case of passed "$name" argument looks like
85+ * a special type name or {@see false} instead.
8886 */
89- public function isBuiltin ( ): bool
87+ public static function isLooksLikeSpecial ( string $ name ): bool
9088 {
91- return self ::looksLikeBuiltin ( $ this -> value );
89+ return \in_array ( \strtolower ( $ name ), self ::SPECIAL_CLASS_NAME , true );
9290 }
9391
9492 /**
9593 * Returns {@see true} in case of passed "$name" argument looks like
9694 * a builtin type name or {@see false} instead.
9795 */
98- public static function looksLikeBuiltin (string $ value ): bool
96+ public static function isLooksLikeBuiltin (string $ value ): bool
9997 {
10098 return \in_array (\strtolower ($ value ), self ::BUILTIN_TYPE_NAME , true );
10199 }
0 commit comments