|
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\Resolver; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusInvoicingPlugin\Entity\InvoiceInterface; |
|
16
|
|
|
use BitBag\SyliusInvoicingPlugin\FileGenerator\FileGeneratorInterface; |
|
17
|
|
|
use BitBag\SyliusInvoicingPlugin\Repository\InvoiceRepositoryInterface; |
|
18
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
19
|
|
|
|
|
20
|
|
|
final class InvoiceFileResolver implements InvoiceFileResolverInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var InvoiceRepositoryInterface */ |
|
23
|
|
|
private $invoiceFileGenerator; |
|
24
|
|
|
|
|
25
|
|
|
/** @var InvoiceRepositoryInterface */ |
|
26
|
|
|
private $invoiceRepository; |
|
27
|
|
|
|
|
28
|
|
|
/** @var InvoiceRepositoryInterface */ |
|
29
|
|
|
private $invoiceEntityManager; |
|
30
|
|
|
|
|
31
|
|
|
/** @var InvoiceRepositoryInterface */ |
|
32
|
|
|
private $environment; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct( |
|
35
|
|
|
FileGeneratorInterface $invoiceFileGenerator, |
|
36
|
|
|
InvoiceRepositoryInterface $invoiceRepository, |
|
37
|
|
|
EntityManagerInterface $invoiceEntityManager, |
|
38
|
|
|
string $environment |
|
39
|
|
|
) { |
|
40
|
|
|
$this->invoiceFileGenerator = $invoiceFileGenerator; |
|
|
|
|
|
|
41
|
|
|
$this->invoiceRepository = $invoiceRepository; |
|
42
|
|
|
$this->invoiceEntityManager = $invoiceEntityManager; |
|
|
|
|
|
|
43
|
|
|
$this->environment = $environment; |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function resolveInvoicePath(InvoiceInterface $invoice): string |
|
47
|
|
|
{ |
|
48
|
|
|
if (null === $invoice->getPath() || (null !== $invoice->getPath() && 'prod' !== $this->environment)) { |
|
49
|
|
|
$invoiceFilename = $this->invoiceFileGenerator->generateFile($invoice); |
|
50
|
|
|
|
|
51
|
|
|
$invoice->setPath($invoiceFilename); |
|
52
|
|
|
$this->invoiceEntityManager->flush(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $this->invoiceFileGenerator->getFilesDirectoryPath() . DIRECTORY_SEPARATOR . $invoice->getPath(); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.