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

BinaryPathAwareTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBinary() 0 3 2
A setBinary() 0 8 1
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
use Gmi\Toolkit\Pdftk\Util\FileChecker;
18
19
/**
20
 * @internal
21
 */
22
trait BinaryPathAwareTrait
23
{
24
    /**
25
     * @var string PDF tool binary including full path
26
     */
27
    private $binaryPath;
28
29
    /**
30
     * Set PDF tool binary to use.
31
     *
32
     * @throws FileNotFoundException
33
     */
34
    public function setBinary(string $binaryPath): self
35
    {
36
        $fileChecker = new FileChecker();
37
        $fileChecker->checkFileExists($binaryPath, 'Binary "%s" not found!');
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