Passed
Push — master ( 133ff2...246377 )
by Luiz Kim
02:06
created

ContractService::genetateFromModel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 13
rs 9.9666
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
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
    $this->manager->persist($file);
29
    $this->manager->flush();
30
31
    return $data;
32
  }
33
34
  public function getContractPDFContent(Contract $contract): string
35
  {
36
    $content = $contract->getContractFile()->getContent();
37
38
    if ($contract->getContractFile()->getExtension() == 'pdf')
39
      return $content;
40
41
    if (empty($content)) {
42
      throw new \Exception(
43
        sprintf('Houve um erro ao gerar o PDF')
44
      );
45
    }
46
47
    return $this->pdf->convertHtmlToPdf($content);
48
  }
49
50
51
52
}
53