| Conditions | 12 |
| Paths | 62 |
| Total Lines | 63 |
| Code Lines | 37 |
| 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 |
||
| 38 | private function generatePrintData(Order $order, string $printType, string $deviceType) |
||
| 39 | { |
||
| 40 | if ($deviceType !== 'cielo') { |
||
| 41 | return ['error' => 'Unsupported device type']; |
||
| 42 | } |
||
| 43 | |||
| 44 | if ($printType === 'pos') { |
||
| 45 | $text = "PEDIDO #" . $order->getId() . "\n"; |
||
| 46 | $text .= "Data: " . $order->getOrderDate()->format('d/m/Y H:i') . "\n"; |
||
| 47 | |||
| 48 | // Correção: Verificar explicitamente se getClient() é null |
||
| 49 | $client = $order->getClient(); |
||
| 50 | $text .= "Cliente: " . ($client !== null ? $client->getName() : 'Não informado') . "\n"; |
||
| 51 | |||
| 52 | $text .= "Total: R$ " . number_format($order->getPrice(), 2, ',', '.') . "\n"; |
||
| 53 | $text .= "------------------------\n"; |
||
| 54 | |||
| 55 | // Agrupar produtos por fila diretamente |
||
| 56 | $queues = []; |
||
| 57 | foreach ($order->getOrderProducts() as $orderProduct) { |
||
| 58 | $queue = $orderProduct->getQueue(); |
||
| 59 | $queueName = $queue ? $queue->getQueue() : 'Sem fila definida'; |
||
| 60 | if (!isset($queues[$queueName])) { |
||
| 61 | $queues[$queueName] = []; |
||
| 62 | } |
||
| 63 | $queues[$queueName][] = $orderProduct; |
||
| 64 | } |
||
| 65 | |||
| 66 | // Exibir produtos organizados por fila |
||
| 67 | foreach ($queues as $queueName => $products) { |
||
| 68 | $text .= strtoupper($queueName) . ":\n"; |
||
| 69 | foreach ($products as $orderProduct) { |
||
| 70 | $product = $orderProduct->getProduct(); |
||
| 71 | $unit = $product->getProductUnit()->getProductUnit(); |
||
| 72 | $quantity = $orderProduct->getQuantity(); |
||
| 73 | |||
| 74 | $text .= "- " . $product->getProduct() . " (" . $quantity . " " . $unit . ")\n"; |
||
| 75 | $text .= " R$ " . number_format($product->getPrice() * $quantity, 2, ',', '.') . "\n"; |
||
| 76 | |||
| 77 | // Verifica se o produto é customizado |
||
| 78 | if ($product->getType() === 'custom') { |
||
| 79 | $text .= " Personalizações:\n"; |
||
| 80 | $productGroupProducts = $this->entityManager->getRepository(ProductGroupProduct::class) |
||
| 81 | ->findBy(['product' => $product->getId()]); |
||
| 82 | |||
| 83 | foreach ($productGroupProducts as $pgp) { |
||
| 84 | $childProduct = $pgp->getProductChild(); |
||
| 85 | if ($childProduct) { |
||
| 86 | $text .= " - " . $childProduct->getProduct() . " (" . $pgp->getQuantity() . " " . $childProduct->getProductUnit()->getProductUnit() . ")\n"; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | $text .= "\n"; |
||
| 92 | } |
||
| 93 | |||
| 94 | $text .= "------------------------\n"; |
||
| 95 | $text .= "Status: " . $order->getStatus()->getStatus() . "\n"; |
||
| 96 | |||
| 97 | return $text; |
||
| 98 | } |
||
| 99 | |||
| 100 | return ['error' => 'Unsupported print type']; |
||
| 101 | } |
||
| 102 | } |
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