| Conditions | 7 | 
| Paths | 10 | 
| Total Lines | 58 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1);  | 
            ||
| 52 | public function save()  | 
            ||
| 53 |     { | 
            ||
| 54 | $dbHandler = Suricate::Database(true);  | 
            ||
| 55 | |||
| 56 |         if ($this->parent_id != '') { | 
            ||
| 57 | // 1st step : delete all records for current parent_id  | 
            ||
| 58 | $sql = "DELETE FROM `" . static::SQL_RELATION_TABLE_NAME . "`";  | 
            ||
| 59 | $sql .= " WHERE";  | 
            ||
| 60 | $sql .= " " . static::PARENT_ID_NAME . "=:parent_id";  | 
            ||
| 61 | |||
| 62 | $sqlParams = [];  | 
            ||
| 63 | $sqlParams['parent_id'] = $this->parent_id;  | 
            ||
| 64 | |||
| 65 | $dbHandler->query($sql, $sqlParams);  | 
            ||
| 66 | |||
| 67 | // 2nd step : create items that are not saved in db  | 
            ||
| 68 |             foreach ($this->items as &$currentItem) { | 
            ||
| 69 |                 if ($currentItem->{$currentItem->getTableIndex()} == '') { | 
            ||
| 70 | $currentItem->save();  | 
            ||
| 71 | }  | 
            ||
| 72 | |||
| 73 | //3rd step : create the mapping  | 
            ||
| 74 | $sqlParams = [];  | 
            ||
| 75 | |||
| 76 | $sql = "INSERT INTO `" . static::SQL_RELATION_TABLE_NAME . "`";  | 
            ||
| 77 | $sql .= " (`" . static::PARENT_ID_NAME . "`, `" . static::MAPPING_ID_NAME. "`";  | 
            ||
| 78 |                 if (count($this->additionalMappingFieldList)) { | 
            ||
| 79 | $sql .= ', ' . implode(  | 
            ||
| 80 | ",",  | 
            ||
| 81 | array_map(  | 
            ||
| 82 |                             function ($s) { | 
            ||
| 83 | return '`' . $s . '`';  | 
            ||
| 84 | },  | 
            ||
| 85 | $this->additionalMappingFieldList  | 
            ||
| 86 | )  | 
            ||
| 87 | );  | 
            ||
| 88 | }  | 
            ||
| 89 | |||
| 90 | $sql .= ")";  | 
            ||
| 91 | $sql .= " VALUES";  | 
            ||
| 92 | $sql .= "(:parent_id, :id";  | 
            ||
| 93 |                 if (count($this->additionalMappingFieldList)) { | 
            ||
| 94 |                     foreach ($this->additionalMappingFieldList as $additionalField) { | 
            ||
| 95 | $sql .= ',:' . $additionalField;  | 
            ||
| 96 | $sqlParams[$additionalField] = $currentItem->$additionalField;  | 
            ||
| 97 | }  | 
            ||
| 98 | }  | 
            ||
| 99 | |||
| 100 | $sql .= ")";  | 
            ||
| 101 | |||
| 102 | |||
| 103 | $sqlParams['parent_id'] = $this->parent_id;  | 
            ||
| 104 | $sqlParams['id'] = $currentItem->id;  | 
            ||
| 105 | |||
| 106 | $dbHandler->query($sql, $sqlParams);  | 
            ||
| 107 | }  | 
            ||
| 108 | }  | 
            ||
| 109 | }  | 
            ||
| 110 | |||
| 152 | */  |