AbstractDocumentFromTemplate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 34
ccs 11
cts 11
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 19 4
1
<?php
2
3
namespace LPDFBuilder\Generation;
4
5
use setasign\Fpdi\Fpdi;
6
7
abstract class AbstractDocumentFromTemplate extends AbstractDocumentFromImage
8
{
9
    use HasTemplateWithImmutablePagesSize;
10
11
    /**
12
     * @inerhitDoc
13
     */
14 6
    public function generate(): Fpdi
15
    {
16 6
        $templatePath = $this->sourceFileTemplatePath();
17
18 5
        $pdf = new Fpdi();
19
20 5
        $pagesCount = $templatePath ? $pdf->setSourceFile($templatePath) : 1;
21
22 4
        for ($page = 1; $page <= $pagesCount; $page++) {
23 4
            $pdf->AddPage('', [$this->templatePageWidth, $this->templatePageHeight]);
24 4
            if ($templatePath) {
25 4
                $tplId = $pdf->importPage($page);
26 4
                $pdf->useTemplate($tplId, 0, 0, $this->templatePageWidth);
27
            }
28
29 4
            $pdf = $this->applyContent($pdf, $page);
30
        }
31
32 4
        return $pdf;
33
    }
34
35
    /**
36
     * @param  Fpdi  $pdf
37
     * @param  int  $page
38
     * @return Fpdi
39
     */
40
    abstract protected function applyContent(Fpdi $pdf, int $page = 1): Fpdi;
41
}
42