Passed
Push — master ( 246377...a66ce3 )
by Luiz Kim
09:50 queued 07:43
created

ContractService::afterPersist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
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
10
class ContractService
11
{
12
13
  public function __construct(
14
    private EntityManagerInterface $manager,
15
    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...
16
    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...
17
  ) {}
18
19
  public function genetateFromModel(Contract $data)
20
  {
21
    $file = $data->getContractFile();
22
    if (!$file)
23
      $file = new File();
24
25
    $file->setFileType('text');
26
    $file->setExtension('html');
27
    $file->setContent($this->modelService->genetateFromModel($data));
28
    $file->setFileName($data->getContractModel()->getModel());
29
    $file->setPeople($data->getBeneficiary());
30
31
    $this->manager->persist($file);
32
33
    $data->setContractFile($file);
34
    $this->manager->persist($data);
35
    $this->manager->flush();
36
37
    return $data;
38
  }
39
40
  public function getContractPDFContent(Contract $contract): string
41
  {
42
    $content = $contract->getContractFile()->getContent();
43
44
    if ($contract->getContractFile()->getExtension() == 'pdf')
45
      return $content;
46
47
    if (empty($content)) {
48
      throw new \Exception(
49
        sprintf('Houve um erro ao gerar o PDF')
50
      );
51
    }
52
53
    return $this->pdf->convertHtmlToPdf($content);
54
  }
55
56
57
  public function afterPersist(Contract $contract)
58
  {
59
    return  $this->genetateFromModel($contract);
60
  }
61
}
62