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

LocalGenerator::getPdf()   A

Complexity

Conditions 1
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 4
nop 2
dl 0
loc 11
rs 10
c 1
b 0
f 0
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