Test Failed
Push — feature/pdfcpu ( 14c728 )
by Andreas
09:40
created

BinaryPathAwareTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBinary() 0 3 2
A setBinary() 0 9 2
1
<?php
2
/**
3
 * BinaryPathAwareTrait
4
 *
5
 * @copyright 2014-2024 Institute of Legal Medicine, Medical University of Innsbruck
6
 * @author Martin Pircher <[email protected]>
7
 * @author Andreas Erhard <[email protected]>
8
 * @license LGPL-3.0-only
9
 * @link http://www.gerichtsmedizin.at/
10
 *
11
 * @package pdftk
12
 */
13
14
namespace Gmi\Toolkit\Pdftk;
15
16
use Gmi\Toolkit\Pdftk\Exception\FileNotFoundException;
17
18
/**
19
 * @internal
20
 */
21
trait BinaryPathAwareTrait
22
{
23
    /**
24
     * @var string PDF tool binary including full path
25
     */
26
    private $binaryPath;
27
28
    /**
29
     * Set PDF tool binary to use.
30
     *
31
     * @throws FileNotFoundException
32
     */
33
    public function setBinary(string $binaryPath): self
34
    {
35
        if (!file_exists($binaryPath)) {
36
            throw new FileNotFoundException(sprintf('Binary "%s" not found', $binaryPath));
37
        }
38
39
        $this->binaryPath = $binaryPath;
40
41
        return $this;
42
    }
43
44
    /**
45
     * Get currently used PDF tool binary.
46
     *
47
     * @param bool $escaped Whether the binary path should be shell escaped
48
     */
49
    public function getBinary(bool $escaped = true): string
50
    {
51
        return $escaped ? escapeshellarg($this->binaryPath) : $this->binaryPath;
52
    }
53
}
54