Passed
Push — master ( 4af149...34b912 )
by Luiz Kim
02:47 queued 18s
created

PurchasingSuggestionAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 2
A __construct() 0 4 1
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\OrderPrintService;
10
11
class PurchasingSuggestionAction
12
{
13
    public function __construct(
14
        private EntityManagerInterface $entityManager,
15
        private OrderPrintService $print
16
    ) {}
17
18
    /**
19
     * @Route("/orders/purchasing-suggestion", name="invoice_inflow", methods={"GET"})
20
     * @IsGranted("ROLE_ADMIN")
21
     */
22
    public function __invoke(Request $request, int $id): JsonResponse
23
    {
24
        $order = $this->entityManager->getRepository(Order::class)->find($id);
25
        if (!$order) {
26
            return new JsonResponse(['error' => 'Order not found'], 404);
27
        }
28
29
        $data = json_decode($request->getContent(), true);
30
        $printType = $data['print-type'] ?? 'pos';
31
        $deviceType = $data['device-type'] ?? 'cielo';
32
33
        $printData = $this->print->generatePrintData($order, $printType, $deviceType);
34
35
        return new JsonResponse($printData);
36
    }
37
}
38