| Conditions | 6 |
| Paths | 6 |
| Total Lines | 40 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | protected function getTableFields($table) |
||
| 24 | { |
||
| 25 | $result = $this->db->execute("DESCRIBE `{$table}`")->fetchAll(PDO::FETCH_ASSOC); |
||
| 26 | $fields = []; |
||
| 27 | |||
| 28 | foreach ($result as $field) { |
||
| 29 | $name = $field['Field']; |
||
| 30 | |||
| 31 | preg_match('#^(\w+)(\((.+)\))?( unsigned)?$#', $field['Type'], $matches); |
||
| 32 | |||
| 33 | $config = [ |
||
| 34 | 'type' => $matches[1], |
||
| 35 | 'null' => ($field['Null'] === 'YES'), |
||
| 36 | 'default' => $field['Default'], |
||
| 37 | 'unsigned' => !empty($matches[4]), |
||
| 38 | 'length' => null, |
||
| 39 | 'values' => null, |
||
| 40 | ]; |
||
| 41 | |||
| 42 | switch ($config['type']) { |
||
| 43 | case 'enum': |
||
| 44 | case 'set': |
||
| 45 | $config['values'] = explode(',', $matches[3]); |
||
| 46 | break; |
||
| 47 | |||
| 48 | default: |
||
| 49 | if (!isset($matches[3])) { |
||
| 50 | $config['length'] = null; |
||
| 51 | } elseif (strpos($matches[3], ',')) { |
||
| 52 | $config['length'] = floatval(str_replace(',', '.', $matches[3])); |
||
| 53 | } else { |
||
| 54 | $config['length'] = intval($matches[3]); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | $fields[$name] = $config; |
||
| 59 | } |
||
| 60 | |||
| 61 | return $fields; |
||
| 62 | } |
||
| 63 | } |
||
| 64 |