| Conditions | 28 |
| Paths | 168 |
| Total Lines | 91 |
| Code Lines | 73 |
| 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 |
||
| 131 | public function setModel($data) { |
||
| 132 | $model = null; |
||
| 133 | $keyCol = null; |
||
| 134 | $uniques = []; |
||
| 135 | foreach ($this->object->params as $param) { |
||
| 136 | $options = $param->options ? json_decode($param->options, true) : []; |
||
| 137 | if ($param->type == 'item_key') { |
||
| 138 | $keyCol = $param->code; |
||
| 139 | break; |
||
| 140 | } elseif (!empty($options['unique'])) { |
||
| 141 | $uniques[$param->code] = $param; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | if ($keyCol && isset($data[$keyCol])) { |
||
| 145 | $objectId = \App::$cur->migrations->findObject((string) $data[$keyCol], $this->object->model); |
||
| 146 | if ($objectId) { |
||
| 147 | $modelName = $this->object->model; |
||
| 148 | $model = $modelName::get($objectId->object_id); |
||
| 149 | } else { |
||
| 150 | $model = new $this->object->model; |
||
| 151 | $model->save(['empty' => true]); |
||
| 152 | $objectId = new \Migrations\Id(); |
||
| 153 | $objectId->object_id = $model->id; |
||
| 154 | $objectId->parse_id = (string) $data[$keyCol]; |
||
| 155 | $objectId->type = $this->object->model; |
||
| 156 | $objectId->save(); |
||
| 157 | \App::$cur->migrations->ids['objectIds'][$this->object->model][$model->id] = $objectId; |
||
| 158 | \App::$cur->migrations->ids['parseIds'][$this->object->model][(string) $data[$keyCol]] = $objectId; |
||
| 159 | } |
||
| 160 | } elseif ($uniques) { |
||
| 161 | $where = []; |
||
| 162 | foreach ($uniques as $code => $param) { |
||
| 163 | if (!isset($data[$code])) { |
||
| 164 | return; |
||
| 165 | } |
||
| 166 | switch ($param->type) { |
||
| 167 | case 'objectLink': |
||
| 168 | $object = \App::$cur->migrations->getMigrationObject($this->walker->migration, $param->value); |
||
| 169 | $objectId = \App::$cur->migrations->findObject((string) $data[$code], $object->model); |
||
| 170 | if (!$objectId) { |
||
| 171 | return; |
||
| 172 | } |
||
| 173 | $modelName = $object->model; |
||
| 174 | $where[] = [$modelName::index(), $objectId->object_id]; |
||
| 175 | break; |
||
| 176 | case 'relation': |
||
| 177 | $modelName = $this->object->model; |
||
| 178 | $relation = $modelName::getRelation($param->value); |
||
| 179 | $objectId = \App::$cur->migrations->findObject((string) $data[$code], $relation['model']); |
||
| 180 | if (!$objectId) { |
||
| 181 | return; |
||
| 182 | } |
||
| 183 | $where[] = [$relation['col'], $objectId->object_id]; |
||
| 184 | break; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | if ($where) { |
||
| 188 | if ($this->parentParam) { |
||
| 189 | $modelName = $this->parentObject->object->model; |
||
| 190 | $relation = $modelName::getRelation($this->parentParam->param->value); |
||
| 191 | if (!empty($relation['type']) && $relation['type'] == 'many' && count($where) == 1) { |
||
| 192 | $relationName = $this->parentParam->param->value; |
||
| 193 | if (!empty($this->parentModel->$relationName(['key' => $where[0][0]])[$where[0][1]])) { |
||
| 194 | return $this->parentModel->$relationName(['key' => $where[0][0]])[$where[0][1]]; |
||
| 195 | } else { |
||
| 196 | $model = new $this->object->model; |
||
| 197 | foreach ($where as $item) { |
||
| 198 | $model->{$item[0]} = $item[1]; |
||
| 199 | } |
||
| 200 | return $model; |
||
| 201 | } |
||
| 202 | } elseif (!empty($relation['type']) && $relation['type'] == 'many') { |
||
| 203 | $where[] = [$relation['col'], $this->parentModel->pk()]; |
||
| 204 | } |
||
| 205 | } elseif ($this->parentObject) { |
||
| 206 | $modelName = $this->parentObject->object->model; |
||
| 207 | $where[] = [$modelName::index(), $this->parentModel->pk()]; |
||
| 208 | } |
||
| 209 | } |
||
| 210 | if ($where) { |
||
| 211 | $modelName = $this->object->model; |
||
| 212 | $model = $modelName::get($where); |
||
| 213 | if (!$model) { |
||
| 214 | $model = new $this->object->model; |
||
| 215 | foreach ($where as $item) { |
||
| 216 | $model->{$item[0]} = $item[1]; |
||
| 217 | } |
||
| 218 | } |
||
| 219 | } |
||
| 220 | } |
||
| 221 | return $model; |
||
| 222 | } |
||
| 223 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths