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.
Completed
Pull Request — master (#16)
by Reyo
10:50 queued 08:42
created

DompdfWrapper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 40.63 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 26
loc 64
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setEventDispatcher() 0 4 1
A streamHtml() 13 13 2
A getPdf() 13 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Events;
15
use Core23\DompdfBundle\Factory\DompdfFactoryInterface;
16
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
17
use Symfony\Component\EventDispatcher\GenericEvent;
18
19
final class DompdfWrapper implements DompdfWrapperInterface
20
{
21
    /**
22
     * @var DompdfFactoryInterface
23
     */
24
    private $dompdfFactory;
25
26
    /**
27
     * @var EventDispatcherInterface
28
     */
29
    private $eventDispatcher;
30
31
    /**
32
     * @param DompdfFactoryInterface $dompdfFactory
33
     */
34
    public function __construct(DompdfFactoryInterface $dompdfFactory)
35
    {
36
        $this->dompdfFactory = $dompdfFactory;
37
    }
38
39
    /**
40
     * Set the event dispatcher.
41
     *
42
     * @param EventDispatcherInterface $eventDispatcher
43
     */
44
    public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
45
    {
46
        $this->eventDispatcher = $eventDispatcher;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 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...
53
    {
54
        $pdf = $this->dompdfFactory->create($options);
55
        $pdf->loadHtml($html);
56
        $pdf->render();
57
58
        if ($this->eventDispatcher instanceof EventDispatcherInterface) {
59
            $event = new GenericEvent($pdf, ['filename' => $filename, 'html' => $html]);
60
            $this->eventDispatcher->dispatch(Events::STREAM, $event);
61
        }
62
63
        $pdf->stream($filename);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 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...
70
    {
71
        $pdf = $this->dompdfFactory->create($options);
72
        $pdf->loadHtml($html);
73
        $pdf->render();
74
75
        if ($this->eventDispatcher instanceof EventDispatcherInterface) {
76
            $event = new GenericEvent($pdf, ['html' => $html]);
77
            $this->eventDispatcher->dispatch(Events::OUTPUT, $event);
78
        }
79
80
        return $pdf->output();
81
    }
82
}
83