@@ -150,6 +150,60 @@ public function __construct(
150150 $ this ->resolve ();
151151 }
152152
153+ private function resolve ():void
154+ {
155+ $ dbType = $ this ->typeWithoutSize (strtolower ($ this ->column ->dbType ));
156+ $ type = $ this ->column ->type ;
157+ $ this ->resolvePosition ();
158+ //Primary Keys
159+ if (array_key_exists ($ type , self ::PK_TYPE_MAP )) {
160+ $ this ->rawParts ['type ' ] = $ type ;
161+ $ this ->fluentParts ['type ' ] = self ::PK_TYPE_MAP [$ type ];
162+ $ this ->isPk = true ;
163+ return ;
164+ }
165+ if (array_key_exists ($ dbType , self ::PK_TYPE_MAP )) {
166+ $ this ->rawParts ['type ' ] = $ dbType ;
167+ $ this ->fluentParts ['type ' ] = self ::PK_TYPE_MAP [$ dbType ];
168+ $ this ->isPk = true ;
169+ return ;
170+ }
171+
172+ if ($ dbType === 'varchar ' ) {
173+ $ type = $ dbType = 'string ' ;
174+ }
175+ $ fluentSize = $ this ->column ->size ? '( ' . $ this ->column ->size . ') ' : '() ' ;
176+ $ rawSize = $ this ->column ->size ? '( ' . $ this ->column ->size . ') ' : '' ;
177+ $ this ->rawParts ['nullable ' ] = $ this ->column ->allowNull ? 'NULL ' : 'NOT NULL ' ;
178+ $ this ->fluentParts ['nullable ' ] = $ this ->column ->allowNull === true ? 'null() ' : 'notNull() ' ;
179+
180+ $ this ->fluentParts ['comment ' ] = $ this ->column ->comment ? 'comment( \'' .$ this ->column ->comment .'\') ' : $ this ->fluentParts ['comment ' ];
181+ $ this ->rawParts ['comment ' ] = $ this ->column ->comment ? 'COMMENT \'' .$ this ->column ->comment .'\'' : $ this ->fluentParts ['comment ' ];
182+
183+ if (array_key_exists ($ dbType , self ::INT_TYPE_MAP )) {
184+ $ this ->fluentParts ['type ' ] = self ::INT_TYPE_MAP [$ dbType ] . $ fluentSize ;
185+ $ this ->rawParts ['type ' ] =
186+ $ this ->column ->dbType . (strpos ($ this ->column ->dbType , '( ' ) !== false ? '' : $ rawSize );
187+ } elseif (array_key_exists ($ type , self ::INT_TYPE_MAP )) {
188+ $ this ->fluentParts ['type ' ] = self ::INT_TYPE_MAP [$ type ] . $ fluentSize ;
189+ $ this ->rawParts ['type ' ] =
190+ $ this ->column ->dbType . (strpos ($ this ->column ->dbType , '( ' ) !== false ? '' : $ rawSize );
191+ } elseif ($ this ->isEnum ()) {
192+ $ this ->resolveEnumType ();
193+ } elseif ($ this ->isDecimal ()) {
194+ $ this ->fluentParts ['type ' ] = $ this ->column ->dbType ;
195+ $ this ->rawParts ['type ' ] = $ this ->column ->dbType ;
196+ } else {
197+ $ this ->fluentParts ['type ' ] = $ type . $ fluentSize ;
198+ $ this ->rawParts ['type ' ] =
199+ $ this ->column ->dbType . (strpos ($ this ->column ->dbType , '( ' ) !== false ? '' : $ rawSize );
200+ }
201+
202+ $ this ->isBuiltinType = $ this ->raw ? false : $ this ->getIsBuiltinType ($ type , $ dbType );
203+
204+ $ this ->resolveDefaultValue ();
205+ }
206+
153207 public function getCode (bool $ quoted = false ):string
154208 {
155209 if ($ this ->isPk ) {
@@ -324,56 +378,6 @@ private function defaultValueArray(array $value):string
324378 return "'{ " . trim (Json::encode ($ value , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT ), '[] ' ) . "}' " ;
325379 }
326380
327- private function resolve ():void
328- {
329- $ dbType = $ this ->typeWithoutSize (strtolower ($ this ->column ->dbType ));
330- $ type = $ this ->column ->type ;
331- $ this ->resolvePosition ();
332- //Primary Keys
333- if (array_key_exists ($ type , self ::PK_TYPE_MAP )) {
334- $ this ->rawParts ['type ' ] = $ type ;
335- $ this ->fluentParts ['type ' ] = self ::PK_TYPE_MAP [$ type ];
336- $ this ->isPk = true ;
337- return ;
338- }
339- if (array_key_exists ($ dbType , self ::PK_TYPE_MAP )) {
340- $ this ->rawParts ['type ' ] = $ dbType ;
341- $ this ->fluentParts ['type ' ] = self ::PK_TYPE_MAP [$ dbType ];
342- $ this ->isPk = true ;
343- return ;
344- }
345-
346- if ($ dbType === 'varchar ' ) {
347- $ type = $ dbType = 'string ' ;
348- }
349- $ fluentSize = $ this ->column ->size ? '( ' . $ this ->column ->size . ') ' : '() ' ;
350- $ rawSize = $ this ->column ->size ? '( ' . $ this ->column ->size . ') ' : '' ;
351- $ this ->rawParts ['nullable ' ] = $ this ->column ->allowNull ? 'NULL ' : 'NOT NULL ' ;
352- $ this ->fluentParts ['nullable ' ] = $ this ->column ->allowNull === true ? 'null() ' : 'notNull() ' ;
353- if (array_key_exists ($ dbType , self ::INT_TYPE_MAP )) {
354- $ this ->fluentParts ['type ' ] = self ::INT_TYPE_MAP [$ dbType ] . $ fluentSize ;
355- $ this ->rawParts ['type ' ] =
356- $ this ->column ->dbType . (strpos ($ this ->column ->dbType , '( ' ) !== false ? '' : $ rawSize );
357- } elseif (array_key_exists ($ type , self ::INT_TYPE_MAP )) {
358- $ this ->fluentParts ['type ' ] = self ::INT_TYPE_MAP [$ type ] . $ fluentSize ;
359- $ this ->rawParts ['type ' ] =
360- $ this ->column ->dbType . (strpos ($ this ->column ->dbType , '( ' ) !== false ? '' : $ rawSize );
361- } elseif ($ this ->isEnum ()) {
362- $ this ->resolveEnumType ();
363- } elseif ($ this ->isDecimal ()) {
364- $ this ->fluentParts ['type ' ] = $ this ->column ->dbType ;
365- $ this ->rawParts ['type ' ] = $ this ->column ->dbType ;
366- } else {
367- $ this ->fluentParts ['type ' ] = $ type . $ fluentSize ;
368- $ this ->rawParts ['type ' ] =
369- $ this ->column ->dbType . (strpos ($ this ->column ->dbType , '( ' ) !== false ? '' : $ rawSize );
370- }
371-
372- $ this ->isBuiltinType = $ this ->raw ? false : $ this ->getIsBuiltinType ($ type , $ dbType );
373-
374- $ this ->resolveDefaultValue ();
375- }
376-
377381 /**
378382 * @param $type
379383 * @param $dbType
0 commit comments