Abstraction::setup()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace phpbu\App\Cli\Executable;
3
4
use phpbu\App\Util\Cli;
5
use SebastianFeldmann\Cli\CommandLine;
6
7
/**
8
 * Execute Binary
9
 *
10
 * @package    phpbu
11
 * @subpackage Backup
12
 * @author     Sebastian Feldmann <[email protected]>
13
 * @copyright  Sebastian Feldmann <[email protected]>
14
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
15
 * @link       http://phpbu.de/
16
 * @since      Class available since Release 2.1.0
17
 */
18
abstract class Abstraction
19
{
20
    /**
21
     * Command name.
22
     *
23
     * @var string
24
     */
25
    protected $cmd;
26
27
    /**
28
     * List of acceptable exit codes.
29
     *
30
     * @var int[]
31
     */
32
    protected $acceptableExitCodes = [0];
33
34
    /**
35
     * Absolute path to command.
36
     *
37
     * @var string
38
     */
39
    protected $binary;
40
41
    /**
42
     * Command to execute
43
     *
44
     * @var \SebastianFeldmann\Cli\CommandLine
45
     */
46
    protected $commandLine;
47
48
    /**
49
     * Setup binary.
50
     *
51
     * @param string $cmd
52
     * @param string $path
53
     */
54 255
    protected function setup(string $cmd, string $path = '')
55
    {
56 255
        $this->cmd    = $cmd;
57 255
        $this->binary = Cli::detectCmdLocation($cmd, $path, Cli::getCommandLocations($this->cmd));
58 255
    }
59
60
    /**
61
     * Returns the CommandLine for this command.
62
     *
63
     * @return \SebastianFeldmann\Cli\CommandLine
64
     */
65 245
    public function getCommandLine() : CommandLine
66
    {
67 245
        return $this->createCommandLine();
68
    }
69
70
    /**
71
     * CommandLine generator.
72
     *
73
     * @return \SebastianFeldmann\Cli\CommandLine
74
     */
75
    abstract protected function createCommandLine() : CommandLine;
76
77
    /**
78
     * Return the command line to execute.
79
     *
80
     * @return string
81
     */
82 230
    public function getCommand() : string
83
    {
84 230
        return $this->getCommandLine()->getCommand();
85
    }
86
87
    /**
88
     * Returns a lost of acceptable exit codes.
89
     *
90
     * @return array
91
     */
92 7
    public function getAcceptableExitCodes() : array
93
    {
94 7
        return $this->acceptableExitCodes;
95
    }
96
97
    /**
98
     * Return the command with masked passwords or keys.
99
     *
100
     * By default just return the original command. Subclasses with password
101
     * arguments have to override this method.
102
     *
103
     * @return string
104
     */
105 10
    public function getCommandPrintable() : string
106
    {
107 10
        return $this->getCommand();
108
    }
109
}
110