| Conditions | 14 |
| Paths | 150 |
| Total Lines | 60 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 18 | public function parse() { |
||
| 19 | if (!Options::$options) { |
||
| 20 | Options::$options = \Ecommerce\Item\Option::getList(); |
||
| 21 | } |
||
| 22 | $options = []; |
||
| 23 | $modelName = 'Ecommerce\Item\Option'; |
||
| 24 | foreach ($this->data['ЗначенияСвойства'] as $opt) { |
||
| 25 | $optionId = \App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option'][$opt['Ид']]->object_id; |
||
| 26 | if (Options::$options[$optionId]->type == 'select') { |
||
| 27 | if (empty($options[$optionId])) { |
||
| 28 | $options[$optionId] = []; |
||
| 29 | } else { |
||
| 30 | if (!Options::$options[$optionId]->advance) { |
||
| 31 | Options::$options[$optionId]->advance = ['multi' => true]; |
||
| 32 | Options::$options[$optionId]->save(); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | $options[$optionId][] = \App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option\Item'][$opt['Значение']]->object_id; |
||
| 36 | } else { |
||
| 37 | $options[$optionId] = $opt['Значение']; |
||
| 38 | } |
||
| 39 | } |
||
| 40 | $itemParams = \Ecommerce\Item\Param::getList(['where' => ['item_id', $this->model->id]]); |
||
| 41 | foreach ($itemParams as $itemParam) { |
||
| 42 | if (Options::$options[$itemParam->item_option_id]->type == 'select') { |
||
| 43 | if (empty($options[$itemParam->item_option_id]) || !in_array($itemParam->value, $options[$itemParam->item_option_id])) { |
||
| 44 | $itemParam->delete(); |
||
| 45 | } else { |
||
| 46 | unset($options[$itemParam->item_option_id][array_search($itemParam->value, $options[$itemParam->item_option_id])]); |
||
| 47 | } |
||
| 48 | } else { |
||
| 49 | if (empty($options[$itemParam->item_option_id])) { |
||
| 50 | $itemParam->delete(); |
||
| 51 | } else { |
||
| 52 | $itemParam->value = $options[$itemParam->item_option_id]; |
||
| 53 | $itemParam->save(); |
||
| 54 | unset($options[$itemParam->item_option_id]); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | foreach ($options as $optionId => $values) { |
||
| 59 | if (is_array($values)) { |
||
| 60 | foreach ($values as $value) { |
||
| 61 | $itemParam = new \Ecommerce\Item\Param([ |
||
| 62 | 'item_option_id' => $optionId, |
||
| 63 | 'item_id' => $this->model->id, |
||
| 64 | 'value' => $value |
||
| 65 | ]); |
||
| 66 | $itemParam->save(); |
||
| 67 | } |
||
| 68 | } else { |
||
| 69 | $itemParam = new \Ecommerce\Item\Param([ |
||
| 70 | 'item_option_id' => $optionId, |
||
| 71 | 'item_id' => $this->model->id, |
||
| 72 | 'value' => $values |
||
| 73 | ]); |
||
| 74 | $itemParam->save(); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 80 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.