| Conditions | 5 |
| Paths | 1 |
| Total Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | protected function loadTableFields(string $table): array |
||
| 18 | { |
||
| 19 | $result = $this->pdo->query("DESCRIBE `{$table}`")->fetchAll(PDO::FETCH_ASSOC); |
||
| 20 | |||
| 21 | return array_map( |
||
| 22 | function ($field) { |
||
| 23 | preg_match('#^(\w+)(\((.+)\))?( unsigned)?#', $field['Type'], $matches); |
||
| 24 | |||
| 25 | $info = [ |
||
| 26 | 'name' => $field['Field'], |
||
| 27 | 'type' => $matches[1], |
||
| 28 | 'null' => ($field['Null'] === 'YES'), |
||
| 29 | 'default' => $field['Default'], |
||
| 30 | 'unsigned' => !empty($matches[4]), |
||
| 31 | 'length' => null, |
||
| 32 | 'values' => null, |
||
| 33 | ]; |
||
| 34 | |||
| 35 | switch ($info['type']) { |
||
| 36 | case 'enum': |
||
| 37 | case 'set': |
||
| 38 | $info['values'] = explode(',', $matches[3]); |
||
| 39 | break; |
||
| 40 | default: |
||
| 41 | if (!isset($matches[3])) { |
||
| 42 | $info['length'] = null; |
||
| 43 | } elseif (strpos($matches[3], ',')) { |
||
| 44 | $info['length'] = floatval(str_replace(',', '.', $matches[3])); |
||
| 45 | } else { |
||
| 46 | $info['length'] = intval($matches[3]); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | return $info; |
||
| 51 | }, |
||
| 52 | $result |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | } |
||
| 56 |