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