@@ -69,7 +69,7 @@ final class TypeGenerator
6969 *
7070 * @throws InvalidArgumentException
7171 */
72- public static function fromTypeString ($ type ): TypeGenerator
72+ public static function fromTypeString (string $ type ): TypeGenerator
7373 {
7474 [$ nullable , $ trimmedNullable ] = self ::trimNullable ($ type );
7575 [$ wasTrimmed , $ trimmedType ] = self ::trimType ($ trimmedNullable );
@@ -97,7 +97,7 @@ public static function fromTypeString($type): TypeGenerator
9797
9898 $ instance = new self ();
9999
100- $ instance ->type = $ trimmedType ;
100+ $ instance ->type = $ isInternalPhpType ? $ trimmedType : $ trimmedNullable ;
101101 $ instance ->nullable = $ nullable ;
102102 $ instance ->isInternalPhpType = $ isInternalPhpType ;
103103
@@ -113,27 +113,18 @@ public function type(): string
113113 return $ this ->type ;
114114 }
115115
116- public function generate (): NodeAbstract
116+ public function isNullable (): bool
117117 {
118- $ nullable = $ this ->nullable ? '? ' : '' ;
119-
120- // TODO nullable
121-
122- if ($ this ->isInternalPhpType ) {
123- return new Node \Identifier (\strtolower ($ this ->type ));
124- // return $nullable . strtolower($this->type);
125- }
126-
127- return new Node \Name ($ this ->type );
128- // return $nullable . '\\' . $this->type;
118+ return $ this ->nullable ;
129119 }
130120
131- /**
132- * @return string the cleaned type string
133- */
134- public function __toString (): string
121+ public function generate (): NodeAbstract
135122 {
136- return \ltrim ($ this ->generate (), '? \\' );
123+ $ type = $ this ->isInternalPhpType
124+ ? new Node \Identifier (\strtolower ($ this ->type ))
125+ : new Node \Name ($ this ->type );
126+
127+ return $ this ->nullable ? new Node \NullableType ($ type ) : $ type ;
137128 }
138129
139130 /**
@@ -142,7 +133,7 @@ public function __toString(): string
142133 * @return bool[]|string[] ordered tuple, first key represents whether the type is nullable, second is the
143134 * trimmed string
144135 */
145- private static function trimNullable ($ type ): array
136+ private static function trimNullable (string $ type ): array
146137 {
147138 if (0 === \strpos ($ type , '? ' )) {
148139 return [true , \substr ($ type , 1 )];
@@ -157,7 +148,7 @@ private static function trimNullable($type): array
157148 * @return bool[]|string[] ordered tuple, first key represents whether the values was trimmed, second is the
158149 * trimmed string
159150 */
160- private static function trimType ($ type ): array
151+ private static function trimType (string $ type ): array
161152 {
162153 if (0 === \strpos ($ type , '\\' )) {
163154 return [true , \substr ($ type , 1 )];
@@ -171,7 +162,7 @@ private static function trimType($type): array
171162 *
172163 * @return bool
173164 */
174- private static function isInternalPhpType ($ type ): bool
165+ private static function isInternalPhpType (string $ type ): bool
175166 {
176167 return \in_array (\strtolower ($ type ), self ::$ internalPhpTypes , true );
177168 }
0 commit comments