| Total Complexity | 52 |
| Total Lines | 234 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ProductCombinationService 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 ProductCombinationService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class ProductCombinationService extends BaseService |
||
| 11 | { |
||
| 12 | public function __construct(ProductCombinationRepository $productTagGroup) |
||
| 15 | } |
||
| 16 | |||
| 17 | public function create(array $attributes, $productId) |
||
| 18 | { |
||
| 19 | if (isset($attributes['selected_attribute_ids'])) { |
||
| 20 | $check = $this->repo->getModelAttributeCombination()->leftJoin($this->repo->getModel()->getTable(), $this->repo->getModel()->getTable().'.id', '=', $this->repo->getModelAttributeCombination()->getTable().'.product_attribute_id') |
||
| 21 | ->where($this->repo->getModel()->getTable().'.product_id', '=', $productId); |
||
| 22 | |||
| 23 | if (isset($attributes['selected_attribute_ids'])) { |
||
| 24 | $check->where(function ($query) use ($attributes) { |
||
| 25 | $query->whereIn($this->repo->getModelAttributeCombination()->getTable().'.attribute_id', $attributes['selected_attribute_ids']); |
||
| 26 | }); |
||
| 27 | } |
||
| 28 | |||
| 29 | if ($check->get()->count()) { |
||
| 30 | $newData = array(); |
||
| 31 | foreach ($check->get() as $row) { |
||
| 32 | $newData[$row['product_attribute_id']] = $row->productAttribute->combinations->toArray(); |
||
| 33 | } |
||
| 34 | |||
| 35 | foreach ($newData as $row) { |
||
| 36 | if (count($row) == count($attributes['selected_attribute_ids'])) { |
||
| 37 | $i = 0; |
||
| 38 | foreach ($row as $newRow) { |
||
| 39 | if (in_array($newRow['attribute_id'], $attributes['selected_attribute_ids'])) { |
||
| 40 | $i++; |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | if (count($row) == $i) { |
||
| 45 | return false; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | $data = $attributes; |
||
| 52 | $data['modified_by_user_id'] = auth('hideyobackend')->user()->id; |
||
| 53 | $data['product_id'] = $productId; |
||
| 54 | |||
| 55 | $new = $this->repo->getModel(); |
||
| 56 | $new->fill($data); |
||
| 57 | $new->save(); |
||
| 58 | |||
| 59 | if (isset($attributes['selected_attribute_ids'])) { |
||
| 60 | foreach ($attributes['selected_attribute_ids'] as $row) { |
||
| 61 | $newData = array( |
||
| 62 | 'attribute_id' => $row, |
||
| 63 | 'product_attribute_id' => $new->id, |
||
| 64 | |||
| 65 | ); |
||
| 66 | |||
| 67 | $ok = new ProductAttributeCombination; |
||
| 68 | $ok->fill($newData); |
||
| 69 | $ok->save(); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | return $new; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | public function updateById(array $attributes, $productId, $productAttributeId) |
||
| 145 | } |
||
| 146 | |||
| 147 | |||
| 148 | public function increaseAmounts($products) |
||
| 149 | { |
||
| 150 | if ($products->count()) { |
||
| 151 | foreach ($products as $product) { |
||
| 152 | if ($product->product_attribute_id) { |
||
| 153 | $model = $this->find($product->product_attribute_id); |
||
| 154 | $attributes = array( |
||
| 155 | 'amount' => $model->amount + $product->amount |
||
| 156 | ); |
||
| 157 | |||
| 158 | $model->fill($attributes); |
||
| 159 | $model->save(); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | public function reduceAmounts($products) |
||
| 177 | } |
||
| 178 | } |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | |||
| 183 | public function selectAllByProductCategoryId($productCategoryId, $shopId) { |
||
| 184 | return $this->repo->selectAllByProductCategoryId($productCategoryId, $shopId); |
||
| 185 | } |
||
| 186 | |||
| 187 | public function generatePulldowns($product, $productAttributeId, $attributeLeadingGroup = false, $secondAttributeId = false) |
||
| 244 | } |
||
| 245 | |||
| 246 | |||
| 247 | } |
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