| Conditions | 2 |
| Paths | 10 |
| Total Lines | 66 |
| Code Lines | 19 |
| 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 |
||
| 29 | public function updateProductInventory(): void |
||
| 30 | { |
||
| 31 | |||
| 32 | $sql = "INSERT INTO `product_inventory` ( |
||
| 33 | `inventory_id`, |
||
| 34 | `product_id`, |
||
| 35 | `product_unity_id`, |
||
| 36 | `available`, |
||
| 37 | `ordered`, |
||
| 38 | `transit`, |
||
| 39 | `minimum`, |
||
| 40 | `maximum`, |
||
| 41 | `sales` |
||
| 42 | ) |
||
| 43 | SELECT |
||
| 44 | op.`inventory_id`, |
||
| 45 | op.`product_id`, |
||
| 46 | p.`product_unity_id`, |
||
| 47 | (SUM(CASE WHEN o.`order_type` = 'purchasing' AND o.`status_id` IN (:purchasing_status) THEN op.`quantity` ELSE 0 END) - |
||
| 48 | SUM(CASE WHEN o.`order_type` = 'sale' AND o.`status_id` IN (:sales_status) THEN op.`quantity` ELSE 0 END)) AS `available`, |
||
| 49 | SUM(CASE WHEN o.`order_type` = 'purchasing' AND o.`status_id` IN (:ordered_status) THEN op.`quantity` ELSE 0 END) AS `ordered`, |
||
| 50 | SUM(CASE WHEN o.`order_type` = 'purchasing' AND o.`status_id` IN (:transit_status) THEN op.`quantity` ELSE 0 END) AS `transit`, |
||
| 51 | 0 AS `minimum`, |
||
| 52 | 0 AS `maximum`, |
||
| 53 | SUM(CASE WHEN o.`order_type` = 'sale' AND o.`status_id` IN (:sales_status) THEN op.`quantity` ELSE 0 END) AS `sales` |
||
| 54 | FROM `orders` o |
||
| 55 | JOIN `order_product` op ON o.`id` = op.`order_id` |
||
| 56 | JOIN `product` p ON op.`product_id` = p.`id` |
||
| 57 | WHERE o.`order_type` IN ('purchasing', 'sale') |
||
| 58 | AND o.`status_id` IN (:all_status) |
||
| 59 | AND p.`type` IN ('product', 'feedstock') |
||
| 60 | AND ( |
||
| 61 | (o.`order_type` = 'sale' AND o.`provider_id` IN (:provider_id)) |
||
| 62 | OR |
||
| 63 | (o.`order_type` = 'purchasing' AND o.`client_id` IN (:client_id)) |
||
| 64 | ) |
||
| 65 | GROUP BY op.`inventory_id`, op.`product_id`, p.`product_unity_id` |
||
| 66 | ON DUPLICATE KEY UPDATE |
||
| 67 | `available` = VALUES(`available`), |
||
| 68 | `ordered` = VALUES(`ordered`), |
||
| 69 | `transit` = VALUES(`transit`), |
||
| 70 | `sales` = VALUES(`sales`) |
||
| 71 | "; |
||
| 72 | |||
| 73 | |||
| 74 | $purchasingStatus = [7]; |
||
| 75 | $orderedStatus = [5]; |
||
| 76 | $transitStatus = [6]; |
||
| 77 | $salesStatus = [6]; |
||
| 78 | $companies = [1, 2, 3]; |
||
| 79 | $allStatus = array_unique(array_merge($purchasingStatus, $orderedStatus, $transitStatus, $salesStatus)); |
||
| 80 | |||
| 81 | try { |
||
| 82 | $stmt = $this->manager->getConnection()->prepare($sql); |
||
| 83 | |||
| 84 | $stmt->bindValue('purchasing_status', implode(',', $purchasingStatus), \PDO::PARAM_STR); |
||
| 85 | $stmt->bindValue('sales_status', implode(',', $salesStatus), \PDO::PARAM_STR); |
||
| 86 | $stmt->bindValue('ordered_status', implode(',', $orderedStatus), \PDO::PARAM_STR); |
||
| 87 | $stmt->bindValue('transit_status', implode(',', $transitStatus), \PDO::PARAM_STR); |
||
| 88 | $stmt->bindValue('all_status', implode(',', $allStatus), \PDO::PARAM_STR); |
||
| 89 | $stmt->bindValue('provider_id', implode(',', $companies), \PDO::PARAM_STR); |
||
| 90 | $stmt->bindValue('client_id', implode(',', $companies), \PDO::PARAM_STR); |
||
| 91 | |||
| 92 | $stmt->executeQuery(); |
||
| 93 | } catch (\Exception $e) { |
||
| 94 | throw new \Exception("Erro ao atualizar o estoque: " . $e->getMessage()); |
||
| 95 | } |
||
| 98 |
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