| Conditions | 10 |
| Paths | 98 |
| Total Lines | 37 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 |
||
| 74 | private function startObjectParse($object_id, &$data) { |
||
| 75 | $objectParser = new Parser\Object(); |
||
| 76 | $objectParser->object = is_object($object_id) ? $object_id : \App::$cur->migrations->getMigrationObject($object_id); |
||
| 77 | $objectParser->data = $data; |
||
| 78 | $objectParser->walker = $this; |
||
| 79 | $ids = $objectParser->parse(); |
||
| 80 | |||
| 81 | if ($objectParser->object->clear && json_decode($objectParser->object->clear, true)) { |
||
| 82 | |||
| 83 | $where = json_decode($objectParser->object->clear, true); |
||
| 84 | if (!$where) { |
||
| 85 | $where = []; |
||
| 86 | } else { |
||
| 87 | $where = [[$where]]; |
||
| 88 | } |
||
| 89 | if ($ids) { |
||
| 90 | $where[] = ['id', implode(',', $ids), 'NOT IN']; |
||
| 91 | } |
||
| 92 | if (empty(\App::$cur->migrations->ids['objectIds'])) { |
||
| 93 | \App::$cur->migrations->loadObjectIds($objectParser->object->model); |
||
| 94 | } |
||
| 95 | if (!empty(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model])) { |
||
| 96 | $where[] = ['id', implode(',', array_keys(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model])), 'IN']; |
||
| 97 | } |
||
| 98 | $modelName = $objectParser->object->model; |
||
| 99 | $objects = $modelName::getList(['where' => $where]); |
||
| 100 | foreach ($objects as $object) { |
||
| 101 | $objectId = \App::$cur->migrations->findParse($object->id, $objectParser->object->model); |
||
| 102 | if ($objectId) { |
||
| 103 | $objectId->delete(); |
||
| 104 | unset(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model][$object->id]); |
||
| 105 | unset(\App::$cur->migrations->ids['parseIds'][$objectParser->object->model][$objectId->parse_id]); |
||
| 106 | } |
||
| 107 | $object->delete(); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 113 |