Passed
Push — master ( 5b94d6...6e3c1d )
by Luiz Kim
02:41
created

PrintOrderAction::generatePrintData()   C

Complexity

Conditions 15
Paths 50

Size

Total Lines 76
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 12
Bugs 0 Features 0
Metric Value
cc 15
eloc 47
c 12
b 0
f 0
nc 50
nop 3
dl 0
loc 76
rs 5.9166

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
namespace ControleOnline\Controller;
4
5
use Symfony\Component\HttpFoundation\Request;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Request was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\HttpFoundation\JsonResponse;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\JsonResponse was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use ControleOnline\Entity\Order;
9
use ControleOnline\Service\PrintService;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Service\PrintService was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class PrintOrderAction
12
{
13
14
15
    public function __construct(
16
        private EntityManagerInterface $entityManager,
17
        private PrintService $print
18
    ) {}
19
20
    public function __invoke(Request $request, int $id): JsonResponse
21
    {
22
        $order = $this->entityManager->getRepository(Order::class)->find($id);
23
        if (!$order) {
24
            return new JsonResponse(['error' => 'Order not found'], 404);
25
        }
26
27
        $data = json_decode($request->getContent(), true);
28
        $printType = $data['print-type'] ?? 'pos';
29
        $deviceType = $data['device-type'] ?? 'cielo';
30
31
        $printData = $this->print->generatePrintData($order, $printType, $deviceType);
32
33
        return new JsonResponse($printData);
34
    }
35
}
36