InvoiceFileResolver::resolveInvoicePath()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.2
cc 4
eloc 6
nc 2
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\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;
0 ignored issues
show
Documentation Bug introduced by
$invoiceFileGenerator is of type object<BitBag\SyliusInvo...FileGeneratorInterface>, but the property $invoiceFileGenerator was declared to be of type object<BitBag\SyliusInvo...iceRepositoryInterface>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

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.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
41
        $this->invoiceRepository = $invoiceRepository;
42
        $this->invoiceEntityManager = $invoiceEntityManager;
0 ignored issues
show
Documentation Bug introduced by
$invoiceEntityManager is of type object<Doctrine\ORM\EntityManagerInterface>, but the property $invoiceEntityManager was declared to be of type object<BitBag\SyliusInvo...iceRepositoryInterface>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

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.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
43
        $this->environment = $environment;
0 ignored issues
show
Documentation Bug introduced by
It seems like $environment of type string is incompatible with the declared type object<BitBag\SyliusInvo...iceRepositoryInterface> of property $environment.

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...
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