Passed
Pull Request — main (#54)
by Thierry
13:54
created

LocalGenerator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 22
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getPdf() 0 11 1
1
<?php
2
3
namespace Siak\Tontine\Service\Report\Pdf;
4
5
use HeadlessChromium\Browser;
6
7
class LocalGenerator implements GeneratorInterface
8
{
9
    /**
10
     * @param Browser $browser
11
     */
12
    public function __construct(private Browser $browser)
13
    {}
14
15
    /**
16
     * @inheritDoc
17
     */
18
    public function getPdf(string $html, array $config): string
19
    {
20
        try
21
        {
22
            $page = $this->browser->createPage();
23
            $page->setHtml($html);
24
            return $page->pdf($config)->getBase64();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $page->pdf($config)->getBase64() could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
25
        }
26
        finally
27
        {
28
            $this->browser->close();
0 ignored issues
show
Bug Best Practice introduced by
The expression ImplicitReturnNode could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
29
        }
30
    }
31
}
32