InvoicePdfFileGenerator::generateFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusInvoicingPlugin\FileGenerator;
14
15
use BitBag\SyliusInvoicingPlugin\Entity\InvoiceInterface;
16
use BitBag\SyliusInvoicingPlugin\Resolver\CompanyDataResolverInterface;
17
use Knp\Snappy\GeneratorInterface;
18
use Symfony\Component\Templating\EngineInterface;
19
20
final class InvoicePdfFileGenerator implements FileGeneratorInterface
21
{
22
    /** @var FilenameGeneratorInterface */
23
    private $filenameGenerator;
24
25
    /** @var FileGeneratorInterface */
26
    private $pdfFileGenerator;
27
28
    /** @var EngineInterface */
29
    private $templatingEngine;
30
31
    /** @var CompanyDataResolverInterface */
32
    private $companyDataResolver;
33
34
    /** @var string */
35
    private $filesPath;
36
37
    public function __construct(
38
        GeneratorInterface $pdfFileGenerator,
39
        EngineInterface $templatingEngine,
40
        CompanyDataResolverInterface $companyDataResolver,
41
        FilenameGeneratorInterface $filenameGenerator,
42
        string $filesPath
43
    ) {
44
        $this->pdfFileGenerator = $pdfFileGenerator;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pdfFileGenerator of type object<Knp\Snappy\GeneratorInterface> is incompatible with the declared type object<BitBag\SyliusInvo...FileGeneratorInterface> of property $pdfFileGenerator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
        $this->templatingEngine = $templatingEngine;
46
        $this->companyDataResolver = $companyDataResolver;
47
        $this->filenameGenerator = $filenameGenerator;
48
        $this->filesPath = $filesPath;
49
    }
50
51
    public function generateFile(InvoiceInterface $invoice): string
52
    {
53
        $html = $this->templatingEngine->render(
54
            'BitBagSyliusInvoicingPlugin::invoice.html.twig', [
55
                'invoice' => $invoice,
56
                'companyData' => $this->companyDataResolver->resolveCompanyData(),
57
            ]
58
        );
59
        $filename = $this->filenameGenerator->generateFilename($invoice);
60
        $path = $this->filesPath . DIRECTORY_SEPARATOR . $filename;
61
62
        $this->pdfFileGenerator->generateFromHtml($html, $path);
0 ignored issues
show
Bug introduced by
The method generateFromHtml() does not seem to exist on object<BitBag\SyliusInvo...FileGeneratorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
64
        return $filename;
65
    }
66
67
    public function getFilesDirectoryPath(): string
68
    {
69
        return $this->filesPath;
70
    }
71
}
72