Passed
Push — master ( 7bdf37...dca01b )
by Luiz Kim
29:37 queued 21:30
created

ContractService::genetateFromModel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 16
c 3
b 0
f 0
dl 0
loc 23
rs 9.7333
cc 2
nc 2
nop 1
1
<?php
2
3
namespace ControleOnline\Service;
4
5
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...
6
7
use ControleOnline\Entity\Contract;
8
use ControleOnline\Entity\File;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\File 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...
9
use ControleOnline\Entity\Status;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\Status 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 ContractService
12
{
13
14
  public function __construct(
15
    private EntityManagerInterface $manager,
16
    private PdfService $pdf,
0 ignored issues
show
Bug introduced by
The type ControleOnline\Service\PdfService 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...
17
    private ModelService $modelService
0 ignored issues
show
Bug introduced by
The type ControleOnline\Service\ModelService 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...
18
  ) {}
19
20
  public function genetateFromModel(Contract $data)
21
  {
22
    $file = $data->getContractFile();
23
    if (!$file)
24
      $file = new File();
25
26
    $file->setFileType('text');
27
    $file->setExtension('html');
28
    $file->setContent($this->modelService->genetateFromModel($data));
29
    $file->setFileName($data->getContractModel()->getModel());
30
    $file->setPeople($data->getBeneficiary());
31
32
    $this->manager->persist($file);
33
34
    $data->setContractFile($file);
35
    $data->setStatus($this->manager->getRepository(Status::class)->findOneBy([
36
      'realStatus' => 'open',
37
      'context' => $data->getStatus()->getContext()
38
    ]));
39
    $this->manager->persist($data);
40
    $this->manager->flush();
41
42
    return $data;
43
  }
44
45
  public function getContractPDFContent(Contract $contract): string
46
  {
47
    $content = $contract->getContractFile()->getContent();
48
49
    if ($contract->getContractFile()->getExtension() == 'pdf')
50
      return $content;
51
52
    if (empty($content)) {
53
      throw new \Exception(
54
        sprintf('Houve um erro ao gerar o PDF')
55
      );
56
    }
57
58
    return $this->pdf->convertHtmlToPdf($content);
59
  }
60
61
62
  public function postPersist(Contract $contract)
63
  {
64
    if ($contract->getStatus()->getRealStatus() == 'open')
65
      return  $this->genetateFromModel($contract);
66
  }
67
}
68