Total Complexity | 43 |
Total Lines | 190 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
Complex classes like Row 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 Row, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
28 | class Row extends SplArrayObject |
||
29 | { |
||
30 | /** |
||
31 | * Row::$model |
||
32 | * |
||
33 | * @var \O2System\Spl\Info\SplClassInfo |
||
34 | */ |
||
35 | private $model; |
||
36 | |||
37 | /** |
||
38 | * Row::$record |
||
39 | * |
||
40 | * @var \O2System\Database\DataObjects\Result\Row\Record |
||
|
|||
41 | */ |
||
42 | private $record; |
||
43 | |||
44 | // ------------------------------------------------------------------------ |
||
45 | |||
46 | /** |
||
47 | * Row::__construct |
||
48 | * |
||
49 | * @param mixed $row |
||
50 | * @param Model $model |
||
51 | */ |
||
52 | public function __construct($row, Model &$model) |
||
53 | { |
||
54 | $this->model = new SplClassInfo($model); |
||
55 | $this->record = $row->getRecord(); |
||
56 | |||
57 | if ( ! models()->has($this->model->getClass())) { |
||
58 | models()->add($model, $this->model->getClass()); |
||
59 | } |
||
60 | |||
61 | if ($row instanceof Database\DataObjects\Result\Row) { |
||
62 | parent::__construct($row->getArrayCopy()); |
||
63 | } elseif (is_array($row)) { |
||
64 | parent::__construct($row); |
||
65 | } |
||
66 | |||
67 | // Append Columns |
||
68 | if (count($model->appendColumns)) { |
||
69 | foreach ($model->appendColumns as $appendColumn) { |
||
70 | $this->offsetSet($appendColumn, $this->offsetGet($appendColumn)); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | models($this->model->getClass())->row = $this; |
||
75 | } |
||
76 | |||
77 | // ------------------------------------------------------------------------ |
||
78 | |||
79 | /** |
||
80 | * Row::offsetGet |
||
81 | * |
||
82 | * @param string $offset |
||
83 | * |
||
84 | * @return mixed |
||
85 | */ |
||
86 | public function offsetGet($offset) |
||
87 | { |
||
88 | if ($this->offsetExists($offset)) { |
||
89 | return parent::offsetGet($offset); |
||
90 | } elseif(strpos($offset, 'record') !== false) { |
||
91 | switch ($offset) { |
||
92 | case 'record': |
||
93 | return $this->record; |
||
94 | break; |
||
95 | case 'record_status': |
||
96 | return $this->record->status; |
||
97 | break; |
||
98 | case 'record_left': |
||
99 | return $this->record->left; |
||
100 | break; |
||
101 | case 'record_right': |
||
102 | return $this->record->right; |
||
103 | break; |
||
104 | case 'record_depth': |
||
105 | return $this->record->depth; |
||
106 | break; |
||
107 | case 'record_ordering': |
||
108 | return $this->record->ordering; |
||
109 | break; |
||
110 | case 'record_create_user': |
||
111 | return $this->record->create->user; |
||
112 | break; |
||
113 | case 'record_create_timestamp': |
||
114 | return $this->record->create->timestamp; |
||
115 | break; |
||
116 | case 'record_update_user': |
||
117 | return $this->record->update->user; |
||
118 | break; |
||
119 | case 'record_update_timestamp': |
||
120 | return $this->record->update->timestamp; |
||
121 | break; |
||
122 | } |
||
123 | } elseif (null !== ($result = $this->__call($offset))) { |
||
124 | return $result; |
||
125 | } |
||
126 | |||
127 | return null; |
||
128 | } |
||
129 | |||
130 | // ------------------------------------------------------------------------ |
||
131 | |||
132 | /** |
||
133 | * Row::__call |
||
134 | * |
||
135 | * @param string $method |
||
136 | * @param array $args |
||
137 | * |
||
138 | * @return bool|\O2System\Framework\Models\Sql\DataObjects\Result|\O2System\Framework\Models\Sql\DataObjects\Result\Row|null |
||
139 | */ |
||
140 | public function __call($method, $args = []) |
||
187 | } |
||
188 | |||
189 | // ------------------------------------------------------------------------ |
||
190 | |||
191 | /** |
||
192 | * Row::delete |
||
193 | * |
||
194 | * @return bool |
||
195 | * @throws \O2System\Spl\Exceptions\RuntimeException |
||
196 | * @throws \Psr\Cache\InvalidArgumentException |
||
197 | */ |
||
198 | public function delete() |
||
218 | } |
||
219 | } |
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