Passed
Push — master ( aea061...82b426 )
by Luiz Kim
07:41
created

CreateNFeAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 17
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 21 2
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 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...
7
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...
8
use ControleOnline\Entity\Order;
9
use ControleOnline\Service\NFeService;
10
11
class CreateNFeAction
12
{
13
14
15
16
    public function __construct(
17
        private EntityManagerInterface $manager,
18
        private NFeService $nFeService
19
    ) {}
20
21
22
23
    public function __invoke(Order $data, Request $request): JsonResponse
24
    {
25
        try {
26
27
            $invoiceTax = $this->nFeService->createNfe($data, 55);
28
            return new JsonResponse([
29
                'response' => [
30
                    'data'    => $data->getId(),
31
                    'invoice_tax' => $invoiceTax->getId(),
32
                    'xml' => $invoiceTax->getInvoice(),
33
                    'count'   => 1,
34
                    'error'   => '',
35
                    'success' => true,
36
                ],
37
            ]);
38
        } catch (\Throwable $th) {
39
            return new JsonResponse([
40
                'response' => [
41
                    'count'   => 0,
42
                    'error'   => $th->getMessage(),
43
                    'success' => false,
44
                ],
45
            ]);
46
        }
47
    }
48
}
49