DownloadInvoiceMenuBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
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\Menu;
14
15
use BitBag\SyliusInvoicingPlugin\Repository\InvoiceRepositoryInterface;
16
use BitBag\SyliusInvoicingPlugin\Resolver\CompanyDataResolverInterface;
17
use Knp\Menu\ItemInterface;
18
use Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent;
19
use Sylius\Component\Core\Model\OrderInterface;
20
21
final class DownloadInvoiceMenuBuilder
22
{
23
    /** @var InvoiceRepositoryInterface */
24
    private $invoiceRepository;
25
26
    /** @var InvoiceRepositoryInterface */
27
    private $companyDataResolver;
28
29
    public function __construct(
30
        InvoiceRepositoryInterface $invoiceRepository,
31
        CompanyDataResolverInterface $companyDataResolver
32
    ) {
33
        $this->invoiceRepository = $invoiceRepository;
34
        $this->companyDataResolver = $companyDataResolver;
0 ignored issues
show
Documentation Bug introduced by
$companyDataResolver is of type object<BitBag\SyliusInvo...yDataResolverInterface>, but the property $companyDataResolver 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...
35
    }
36
37
    public function addItem(OrderShowMenuBuilderEvent $orderShowMenuBuilderEvent): void
38
    {
39
        /** @var OrderInterface $order */
40
        $order = $orderShowMenuBuilderEvent->getOrder();
41
42
        if (null === $this->invoiceRepository->findByOrderId($order->getId())) {
43
            return;
44
        }
45
46
        $menu = $orderShowMenuBuilderEvent->getMenu();
47
48
        if (null === $this->companyDataResolver->resolveCompanyData()) {
49
            $this->addNoCompanyDataInfoMenuItem($menu);
50
51
            return;
52
        }
53
54
        $this->addDownloadInvoiceMenuItem($menu, $order);
55
    }
56
57
    private function addNoCompanyDataInfoMenuItem(ItemInterface $menu): void
58
    {
59
        $menu
60
            ->addChild('download_invoice', [
61
                'route' => 'bitbag_sylius_invoicing_plugin_admin_company_data_index',
62
            ])
63
            ->setAttribute('type', 'link')
64
            ->setLabel('bitbag_sylius_invoicing_plugin.ui.set_invoice_data')
65
            ->setLabelAttribute('icon', 'warning')
66
            ->setLabelAttribute('color', 'yellow')
67
        ;
68
    }
69
70
    private function addDownloadInvoiceMenuItem(ItemInterface $menu, OrderInterface $order): void
71
    {
72
        $menu
73
            ->addChild('download_invoice', [
74
                'route' => 'bitbag_sylius_invoicing_plugin_download_order_invoice',
75
                'routeParameters' => ['orderTokenValue' => $order->getTokenValue()],
76
            ])
77
            ->setAttribute('type', 'link')
78
            ->setLabel('bitbag_sylius_invoicing_plugin.ui.download_invoice')
79
            ->setLabelAttribute('icon', 'download')
80
            ->setLabelAttribute('color', 'blue')
81
        ;
82
    }
83
}
84