@@ -107,44 +107,50 @@ discard block |
||
| 107 | 107 | foreach ($query as $field) { |
| 108 | 108 | $singleField = "\n\t\t'$field->Field' => ["; |
| 109 | 109 | //Type |
| 110 | - if (preg_match('/^([a-z]+)/', $field->Type, $matches) > 0) |
|
| 111 | - $singleField .= "\n\t\t\t'type' => '" . strtoupper($matches[1]) . "',"; |
|
| 110 | + if (preg_match('/^([a-z]+)/', $field->Type, $matches) > 0) { |
|
| 111 | + $singleField .= "\n\t\t\t'type' => '" . strtoupper($matches[1]) . "',"; |
|
| 112 | + } |
|
| 112 | 113 | |
| 113 | 114 | //Constraint |
| 114 | 115 | if (preg_match('/\((.+)\)/', $field->Type, $matches) > 0) { |
| 115 | 116 | //integer , varchar |
| 116 | - if (is_numeric($matches[1])) |
|
| 117 | - $singleField .= "\n\t\t\t'constraint' => " . $matches[1] . ","; |
|
| 117 | + if (is_numeric($matches[1])) { |
|
| 118 | + $singleField .= "\n\t\t\t'constraint' => " . $matches[1] . ","; |
|
| 119 | + } |
|
| 118 | 120 | |
| 119 | 121 | //float , double |
| 120 | - elseif (preg_match('/[\d]+\s?,[\d]+\s?/', $matches[1]) > 0) |
|
| 121 | - $singleField .= "\n\t\t\t'constraint' => '" . $matches[1] . "',"; |
|
| 122 | + elseif (preg_match('/[\d]+\s?,[\d]+\s?/', $matches[1]) > 0) { |
|
| 123 | + $singleField .= "\n\t\t\t'constraint' => '" . $matches[1] . "',"; |
|
| 124 | + } |
|
| 122 | 125 | |
| 123 | 126 | //Enum Fields |
| 124 | 127 | else { |
| 125 | 128 | $values = explode(',', str_replace("'", "", $matches[1])); |
| 126 | 129 | |
| 127 | - if (count($values) == 1) |
|
| 128 | - $singleField .= "\n\t\t\t'constraint' => [" . $this->getGluedString($values) . "],"; |
|
| 129 | - |
|
| 130 | - else |
|
| 131 | - $singleField .= "\n\t\t\t'constraint' => " . $this->getGluedString($values) . ","; |
|
| 130 | + if (count($values) == 1) { |
|
| 131 | + $singleField .= "\n\t\t\t'constraint' => [" . $this->getGluedString($values) . "],"; |
|
| 132 | + } else { |
|
| 133 | + $singleField .= "\n\t\t\t'constraint' => " . $this->getGluedString($values) . ","; |
|
| 134 | + } |
|
| 132 | 135 | } |
| 133 | 136 | } |
| 134 | 137 | |
| 135 | 138 | //if field need null |
| 136 | 139 | $singleField .= "\n\t\t\t'null' => " . (($field->Null == 'YES') ? 'true,' : 'false,'); |
| 137 | 140 | |
| 138 | - if (!is_null($field->Default) && (strpos($field->Default, 'current_timestamp()') === FALSE)) |
|
| 139 | - $singleField .= "\n\t\t\t'default' => '$field->Default',"; |
|
| 141 | + if (!is_null($field->Default) && (strpos($field->Default, 'current_timestamp()') === FALSE)) { |
|
| 142 | + $singleField .= "\n\t\t\t'default' => '$field->Default',"; |
|
| 143 | + } |
|
| 140 | 144 | |
| 141 | 145 | //unsigned |
| 142 | - if (strpos($field->Type, 'unsigned') !== false) |
|
| 143 | - $singleField .= "\n\t\t\t'unsigned' => true,"; |
|
| 146 | + if (strpos($field->Type, 'unsigned') !== false) { |
|
| 147 | + $singleField .= "\n\t\t\t'unsigned' => true,"; |
|
| 148 | + } |
|
| 144 | 149 | |
| 145 | 150 | //autoincrement |
| 146 | - if (strpos($field->Extra, 'auto_increment') !== false) |
|
| 147 | - $singleField .= "\n\t\t\t'auto_increment' => true,"; |
|
| 151 | + if (strpos($field->Extra, 'auto_increment') !== false) { |
|
| 152 | + $singleField .= "\n\t\t\t'auto_increment' => true,"; |
|
| 153 | + } |
|
| 148 | 154 | |
| 149 | 155 | $singleField .= "\n\t\t],"; |
| 150 | 156 | $fieldString .= $singleField; |
@@ -168,22 +174,23 @@ discard block |
||
| 168 | 174 | { |
| 169 | 175 | |
| 170 | 176 | //array consist of one element |
| 171 | - if (count($arr) == 1) |
|
| 172 | - return "'" . strval(array_shift($arr)) . "'"; |
|
| 173 | - |
|
| 174 | - else { |
|
| 177 | + if (count($arr) == 1) { |
|
| 178 | + return "'" . strval(array_shift($arr)) . "'"; |
|
| 179 | + } else { |
|
| 175 | 180 | |
| 176 | 181 | $str = ''; |
| 177 | 182 | if (!$is_assoc) { |
| 178 | 183 | foreach ($arr as $item) { |
| 179 | - if (strlen($item) > 0) |
|
| 180 | - $str .= "'$item', "; |
|
| 184 | + if (strlen($item) > 0) { |
|
| 185 | + $str .= "'$item', "; |
|
| 186 | + } |
|
| 181 | 187 | } |
| 182 | 188 | |
| 183 | 189 | } else { |
| 184 | 190 | foreach ($arr as $index => $item) { |
| 185 | - if (strlen($item) > 0) |
|
| 186 | - $str .= "'$index' => '$item',"; |
|
| 191 | + if (strlen($item) > 0) { |
|
| 192 | + $str .= "'$index' => '$item',"; |
|
| 193 | + } |
|
| 187 | 194 | } |
| 188 | 195 | } |
| 189 | 196 | |
@@ -238,8 +245,9 @@ discard block |
||
| 238 | 245 | { |
| 239 | 246 | $keys = $this->db->getForeignKeyData($table); |
| 240 | 247 | $keyArray = []; |
| 241 | - foreach ($keys as $key) |
|
| 242 | - array_push($keyArray, "\n\t\t\$this->forge->addForeignKey('$key->column_name','$key->foreign_table_name','$key->foreign_column_name','CASCADE','CASCADE');"); |
|
| 248 | + foreach ($keys as $key) { |
|
| 249 | + array_push($keyArray, "\n\t\t\$this->forge->addForeignKey('$key->column_name','$key->foreign_table_name','$key->foreign_column_name','CASCADE','CASCADE');"); |
|
| 250 | + } |
|
| 243 | 251 | |
| 244 | 252 | return implode('', array_unique($keyArray)); |
| 245 | 253 | } |
@@ -300,8 +308,9 @@ discard block |
||
| 300 | 308 | } |
| 301 | 309 | |
| 302 | 310 | //property cast |
| 303 | - if ($field->type == 'tinyint') |
|
| 304 | - $casts[$field->name] = (($field->nullable) ? "?" : '') . "boolean"; |
|
| 311 | + if ($field->type == 'tinyint') { |
|
| 312 | + $casts[$field->name] = (($field->nullable) ? "?" : '') . "boolean"; |
|
| 313 | + } |
|
| 305 | 314 | |
| 306 | 315 | } |
| 307 | 316 | |
@@ -324,14 +333,13 @@ discard block |
||
| 324 | 333 | $fields = $this->db->getFieldData($table); |
| 325 | 334 | |
| 326 | 335 | foreach ($fields as $field) { |
| 327 | - if ($field->primary_key === 1) |
|
| 328 | - $primary_ids[] = $field->name; |
|
| 329 | - |
|
| 330 | - elseif ($field->name == 'created_at' || $field->name == 'updated_at') |
|
| 331 | - continue; |
|
| 332 | - |
|
| 333 | - else |
|
| 334 | - $attributes[] = $field->name; |
|
| 336 | + if ($field->primary_key === 1) { |
|
| 337 | + $primary_ids[] = $field->name; |
|
| 338 | + } elseif ($field->name == 'created_at' || $field->name == 'updated_at') { |
|
| 339 | + continue; |
|
| 340 | + } else { |
|
| 341 | + $attributes[] = $field->name; |
|
| 342 | + } |
|
| 335 | 343 | } |
| 336 | 344 | |
| 337 | 345 | //Model only support single column in primary key getting the first one |
@@ -357,13 +365,16 @@ discard block |
||
| 357 | 365 | */ |
| 358 | 366 | public function validationRules(array $fields) |
| 359 | 367 | { |
| 360 | - if (empty($fields)) return '[]'; |
|
| 368 | + if (empty($fields)) { |
|
| 369 | + return '[]'; |
|
| 370 | + } |
|
| 361 | 371 | |
| 362 | 372 | $rules = []; |
| 363 | 373 | |
| 364 | 374 | foreach ($fields as $field) { |
| 365 | - if (in_array($field->name, ['created_at', 'updated_at'])) |
|
| 366 | - continue; |
|
| 375 | + if (in_array($field->name, ['created_at', 'updated_at'])) { |
|
| 376 | + continue; |
|
| 377 | + } |
|
| 367 | 378 | |
| 368 | 379 | $rule = []; |
| 369 | 380 | |