GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DompdfWrapper::getStreamResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\DompdfBundle\Wrapper;
13
14
use Core23\DompdfBundle\DompdfEvents;
15
use Core23\DompdfBundle\Event\OutputEvent;
16
use Core23\DompdfBundle\Event\StreamEvent;
17
use Core23\DompdfBundle\Exception\PdfException;
18
use Core23\DompdfBundle\Factory\DompdfFactoryInterface;
19
use Symfony\Component\HttpFoundation\StreamedResponse;
20
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
21
22
final class DompdfWrapper implements DompdfWrapperInterface
23
{
24
    /**
25
     * @var DompdfFactoryInterface
26
     */
27
    private $dompdfFactory;
28
29
    /**
30
     * @var EventDispatcherInterface|null
31
     */
32
    private $eventDispatcher;
33
34
    public function __construct(DompdfFactoryInterface $dompdfFactory, EventDispatcherInterface $eventDispatcher = null)
35
    {
36
        $this->dompdfFactory   = $dompdfFactory;
37
        $this->eventDispatcher = $eventDispatcher;
38
    }
39
40 View Code Duplication
    public function streamHtml(string $html, string $filename, array $options = []): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $pdf = $this->dompdfFactory->create($options);
43
        $pdf->loadHtml($html);
44
        $pdf->render();
45
46
        if ($this->eventDispatcher instanceof EventDispatcherInterface) {
47
            $event = new StreamEvent($pdf, $filename, $html);
48
            $this->eventDispatcher->dispatch($event, DompdfEvents::STREAM);
0 ignored issues
show
Documentation introduced by
$event is of type object<Core23\DompdfBundle\Event\StreamEvent>, but the function expects a object<Symfony\Contracts\EventDispatcher\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
        }
50
51
        $pdf->stream($filename, $options);
52
    }
53
54
    public function getStreamResponse(string $html, string $filename, array $options = []): StreamedResponse
55
    {
56
        $response = new StreamedResponse();
57
        $response->setCallback(function () use ($html, $filename, $options): void {
58
            $this->streamHtml($html, $filename, $options);
59
        });
60
61
        return $response;
62
    }
63
64 View Code Duplication
    public function getPdf(string $html, array $options = []): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        $pdf = $this->dompdfFactory->create($options);
67
        $pdf->loadHtml($html);
68
        $pdf->render();
69
70
        if ($this->eventDispatcher instanceof EventDispatcherInterface) {
71
            $event = new OutputEvent($pdf, $html);
72
            $this->eventDispatcher->dispatch($event, DompdfEvents::OUTPUT);
0 ignored issues
show
Documentation introduced by
$event is of type object<Core23\DompdfBundle\Event\OutputEvent>, but the function expects a object<Symfony\Contracts\EventDispatcher\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
73
        }
74
75
        $out = $pdf->output();
76
77
        if (null === $out) {
78
            throw new PdfException('Error creating PDF document');
79
        }
80
81
        return $out;
82
    }
83
}
84