Passed
Branch main (d5171d)
by Andreas
26:52 queued 08:26
created

Pages::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * PDFtk wrapper
4
 *
5
 * @copyright 2014-2024 Institute of Legal Medicine, Medical University of Innsbruck
6
 * @author Andreas Erhard <[email protected]>
7
 * @license LGPL-3.0-only
8
 * @link http://www.gerichtsmedizin.at/
9
 *
10
 * @package pdftk
11
 */
12
13
namespace Gmi\Toolkit\Pdftk;
14
15
/**
16
 * Read PDF page information.
17
 */
18
class Pages
19
{
20
    /**
21
     * Pages.
22
     *
23
     * @var Page[]
24
     */
25
    private $pages = [];
26
27
    /**
28
     * @var WrapperInterface
29
     */
30
    private $wrapper;
31
32
    /**
33
     * Constructor.
34
     */
35 28
    public function __construct(WrapperInterface $wrapper = null)
36
    {
37 28
        $this->wrapper = $wrapper ?: new PdftkWrapper();
38 28
    }
39
40
    /**
41
     * Add page to the pages array.
42
     */
43 20
    public function add(Page $page): self
44
    {
45 20
        $this->pages[] = $page;
46
47 20
        return $this;
48
    }
49
50
    /**
51
     * Returns all pages.
52
     *
53
     * @return Page[]
54
     */
55 21
    public function all(): array
56
    {
57 21
        return $this->pages;
58
    }
59
60
    /**
61
     * Remove all pages.
62
     */
63 2
    public function clear(): self
64
    {
65 2
        $this->pages = [];
66
67 2
        return $this;
68
    }
69
70
    /**
71
     * Imports pages from a PDF file.
72
     *
73
     * @throws PdfException
74
     */
75 10
    public function import(string $infile): self
76
    {
77 10
        $this->wrapper->importPages($this, $infile);
78
79 8
        return $this;
80
    }
81
}
82