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

Pages   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 62
ccs 14
cts 14
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 3 1
A add() 0 5 1
A __construct() 0 3 2
A clear() 0 5 1
A import() 0 5 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