| Conditions | 4 |
| Paths | 6 |
| Total Lines | 23 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 37 | public function insert($object) { |
||
| 38 | $db = classSupernova::$gc->db; |
||
| 39 | |||
| 40 | $query = array(); |
||
| 41 | foreach ($object->exportDbRow(false) as $fieldName => $fieldValue) { |
||
| 42 | // TODO: MORE type detection |
||
| 43 | if(!is_numeric($fieldValue)) { |
||
| 44 | $fieldValue = "'" . $db->db_escape($fieldValue) . "'"; |
||
| 45 | } |
||
| 46 | $query[] = "`{$fieldName}` = {$fieldValue}"; |
||
| 47 | } |
||
| 48 | |||
| 49 | $query = implode(',', $query); |
||
| 50 | if (empty($query)) { |
||
| 51 | // TODO Exceptiion |
||
| 52 | return 0; |
||
| 53 | } |
||
| 54 | |||
| 55 | $db->doquery("INSERT INTO `{{" . $object->getTableName() . "}}` SET " . $query); |
||
| 56 | |||
| 57 | // TODO Exceptiion if db_insert_id() is empty |
||
| 58 | return $object->dbId = $db->db_insert_id(); |
||
| 59 | } |
||
| 60 | |||
| 62 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.