| Total Complexity | 59 |
| Total Lines | 208 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Object often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Object, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class Object extends \InjiObject { |
||
|
|
|||
| 15 | |||
| 16 | public $object; |
||
| 17 | public $parentObject; |
||
| 18 | public $parentModel; |
||
| 19 | public $parentParam; |
||
| 20 | /** |
||
| 21 | * @var \Migrations\Walker |
||
| 22 | */ |
||
| 23 | public $walker; |
||
| 24 | public $data; |
||
| 25 | |||
| 26 | public function parse($preset = []) { |
||
| 42 | } |
||
| 43 | |||
| 44 | private function parseData($data, $preset) { |
||
| 45 | $keyLog = \App::$cur->log->start('start object model set'); |
||
| 46 | $model = $this->setModel($data); |
||
| 47 | \App::$cur->log->end($keyLog); |
||
| 48 | if ($model) { |
||
| 49 | foreach ($preset as $col => $value) { |
||
| 50 | $model->{$col} = $value; |
||
| 51 | } |
||
| 52 | if (defined('mdebug')) { |
||
| 53 | echo " -> objectStart ({$this->object->id}) "; |
||
| 54 | } |
||
| 55 | $walked = []; |
||
| 56 | foreach ($this->object->params as $param) { |
||
| 57 | if (defined('mdebug')) { |
||
| 58 | echo " -> param ($param->id,$param->type,$param->value) "; |
||
| 59 | } |
||
| 60 | if ($model && $param->type && $param->type != 'item_key') { |
||
| 61 | if ($param->type == 'object') { |
||
| 62 | $object = \App::$cur->migrations->getMigrationObject($this->walker->migration, $param->value); |
||
| 63 | $parser = new \Migrations\Parser\Object; |
||
| 64 | $parser->data = &$data[$param->code]; |
||
| 65 | $parser->object = $object; |
||
| 66 | $parser->parentObject = $this; |
||
| 67 | $parser->parentModel = $model; |
||
| 68 | $parser->walker = $this->walker; |
||
| 69 | if (defined('mdebug')) { |
||
| 70 | echo " -> objectParse "; |
||
| 71 | } |
||
| 72 | $parser->parse(); |
||
| 73 | } else { |
||
| 74 | if ($param->type == 'custom') { |
||
| 75 | $parserName = $param->value; |
||
| 76 | } else { |
||
| 77 | $parserName = '\Migrations\Parser\Object\\' . ucfirst($param->type); |
||
| 78 | } |
||
| 79 | $parser = new $parserName; |
||
| 80 | $parser->data = &$data[$param->code]; |
||
| 81 | $parser->param = $param; |
||
| 82 | $parser->model = $model; |
||
| 83 | $parser->walker = $this->walker; |
||
| 84 | $parser->object = $this; |
||
| 85 | if (defined('mdebug')) { |
||
| 86 | echo " -> parser ($parserName) "; |
||
| 87 | } |
||
| 88 | $parser->parse(); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | if (defined('mdebug')) { |
||
| 92 | echo " -> paramEnd ($param->id,$param->type,$param->value) "; |
||
| 93 | } |
||
| 94 | $walked[$param->code] = true; |
||
| 95 | } |
||
| 96 | |||
| 97 | //check unparsed params |
||
| 98 | foreach ($data as $key => $item) { |
||
| 99 | //skip parsed and attribtes |
||
| 100 | if ($key == '@attributes' || !empty($walked[$key])) { |
||
| 101 | continue; |
||
| 102 | } |
||
| 103 | $param = new \Migrations\Migration\Object\Param(); |
||
| 104 | $param->object_id = $this->object->id; |
||
| 105 | $param->code = $key; |
||
| 106 | $param->save(); |
||
| 107 | $className = get_class($this->object); |
||
| 108 | $this->object = $className::get($this->object->id); |
||
| 109 | } |
||
| 110 | if ($model) { |
||
| 111 | if ($this->object->delete_empty && @json_decode($this->object->delete_empty, true)) { |
||
| 112 | $deleteIf = json_decode($this->object->delete_empty, true); |
||
| 113 | foreach ($deleteIf['params'] as $paramId) { |
||
| 114 | if ($model->{$this->object->params[$paramId]->value} === '') { |
||
| 115 | if($model->pk()){ |
||
| 116 | $model->delete(); |
||
| 117 | } |
||
| 118 | return 0; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | if (!$model->pk() || !empty($model->_changedParams)) { |
||
| 123 | $model->save(); |
||
| 124 | } |
||
| 125 | return $model->pk(); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | return 0; |
||
| 129 | } |
||
| 130 | |||
| 131 | public function setModel($data) { |
||
| 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