DownloadOrderInvoice   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A __invoke() 0 10 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\Controller\Action;
14
15
use BitBag\SyliusInvoicingPlugin\Repository\InvoiceRepositoryInterface;
16
use BitBag\SyliusInvoicingPlugin\Resolver\InvoiceFileResolverInterface;
17
use Symfony\Component\HttpFoundation\BinaryFileResponse;
18
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
19
20
final class DownloadOrderInvoice
21
{
22
    /** @var InvoiceRepositoryInterface */
23
    private $invoiceRepository;
24
25
    /** @var InvoiceRepositoryInterface */
26
    private $invoiceFileResolver;
27
28
    public function __construct(
29
        InvoiceRepositoryInterface $invoiceRepository,
30
        InvoiceFileResolverInterface $invoiceFileResolver
31
    ) {
32
        $this->invoiceRepository = $invoiceRepository;
33
        $this->invoiceFileResolver = $invoiceFileResolver;
0 ignored issues
show
Documentation Bug introduced by
$invoiceFileResolver is of type object<BitBag\SyliusInvo...eFileResolverInterface>, but the property $invoiceFileResolver 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...
34
    }
35
36
    public function __invoke(string $orderTokenValue): BinaryFileResponse
37
    {
38
        $invoice = $this->invoiceRepository->findOneByTokenValue($orderTokenValue);
39
        $response = new BinaryFileResponse($this->invoiceFileResolver->resolveInvoicePath($invoice));
40
41
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
42
        $response->headers->set('Content-Type', 'application/pdf');
43
44
        return $response;
45
    }
46
}
47