These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types = 1); |
||
4 | |||
5 | namespace iio\libmergepdf\Driver; |
||
6 | |||
7 | use iio\libmergepdf\Exception; |
||
8 | use iio\libmergepdf\Source\SourceInterface; |
||
9 | use setasign\Fpdi\Fpdi as FpdiFpdf; |
||
10 | use setasign\Fpdi\Tcpdf\Fpdi as FpdiTcpdf; |
||
11 | use setasign\Fpdi\PdfParser\StreamReader; |
||
12 | |||
13 | final class Fpdi2Driver implements DriverInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var FpdiFpdf|FpdiTcpdf |
||
17 | */ |
||
18 | private $fpdi; |
||
19 | |||
20 | /** |
||
21 | * @param FpdiFpdf|FpdiTcpdf $fpdi |
||
22 | */ |
||
23 | public function __construct($fpdi = null) |
||
24 | { |
||
25 | $this->fpdi = $fpdi ?: new FpdiTcpdf; |
||
26 | |||
27 | if (!($this->fpdi instanceof FpdiFpdf) && !($this->fpdi instanceof FpdiTcpdf)) { |
||
28 | throw new \InvalidArgumentException('Constructor argument must be an FPDI instance.'); |
||
29 | } |
||
30 | } |
||
31 | |||
32 | View Code Duplication | public function merge(SourceInterface ...$sources): string |
|
33 | { |
||
34 | $sourceName = ''; |
||
35 | |||
36 | try { |
||
37 | $fpdi = clone $this->fpdi; |
||
38 | |||
39 | foreach ($sources as $source) { |
||
40 | $sourceName = $source->getName(); |
||
41 | $pageCount = $fpdi->setSourceFile(StreamReader::createByString($source->getContents())); |
||
42 | $pageNumbers = $source->getPages()->getPageNumbers() ?: range(1, $pageCount); |
||
43 | |||
44 | foreach ($pageNumbers as $pageNr) { |
||
45 | $template = $fpdi->importPage($pageNr); |
||
46 | $size = $fpdi->getTemplateSize($template); |
||
47 | $fpdi->AddPage( |
||
0 ignored issues
–
show
|
|||
48 | $size['width'] > $size['height'] ? 'L' : 'P', |
||
49 | [$size['width'], $size['height']] |
||
50 | ); |
||
51 | $fpdi->useTemplate($template); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | return $fpdi->Output('', 'S'); |
||
56 | } catch (\Exception $e) { |
||
57 | throw new Exception("'{$e->getMessage()}' in '$sourceName'", 0, $e); |
||
58 | } |
||
59 | } |
||
60 | } |
||
61 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: