Test Failed
Push — main ( 961615...d5171d )
by Andreas
12:44 queued 13s
created

Splitter::buildCommandLines()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 21
ccs 13
cts 13
cp 1
rs 9.8333
cc 3
nc 3
nop 3
crap 3
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
use Gmi\Toolkit\Pdftk\Exception\PdfException;
16
use Gmi\Toolkit\Pdftk\Exception\SplitException;
17
18
/**
19
 * Splits PDF files.
20
 */
21
class Splitter
22
{
23
    /**
24
     * @var WrapperInterface
25
     */
26
    private $wrapper;
27
28
    /**
29
     * Constructor.
30
     */
31
    public function __construct(WrapperInterface $wrapper = null)
32
    {
33
        $this->wrapper = $wrapper ?: new PdftkWrapper();
34 10
    }
35
36 10
    /**
37 10
     * Splits a PDF according to the provided filename => pages mapping.
38
     *
39
     * @param string $inputFile    Filename of the input file which should be split
40
     * @param array  $mapping      Mapping of output filename to page numbers
41
     * @param string $outputFolder Folder where the output files should be stored (without trailing slash).
42
     *                             If the output folder is null, the filenames of the mapping
43
     *                             (which can contain a path) are used as they are.
44
     *
45
     * @throws SplitException if the PDF split fails
46
     */
47
    public function split(string $inputFile, array $mapping, string $outputFolder = null): void
48
    {
49
        try {
50 4
            $this->wrapper->split($inputFile, $mapping, $outputFolder);
51
        } catch (PdfException $e) {
52 4
            throw new SplitException(
53
                sprintf('Failed to split PDF "%s"! Error: %s', $inputFile, $e->getMessage()),
54 4
                0,
55 4
                $e,
56
                $e->getPdfError(),
57
                $e->getPdfOutput()
58 4
            );
59 2
        }
60 2
    }
61
}
62