Completed
Push — master ( c70526...35413c )
by Sebastian
05:26
created

Result   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 128
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCommandResult() 0 4 1
A isSuccessful() 0 4 1
A getReturnCode() 0 4 1
A getCmd() 0 4 1
A getCmdPrintable() 0 4 1
A getStdOut() 0 4 1
A getStdErr() 0 4 1
A isOutputRedirected() 0 4 1
A getRedirectPath() 0 4 1
A getBufferedOutput() 0 4 1
1
<?php
2
namespace phpbu\App\Cli;
3
4
use SebastianFeldmann\Cli\Command\Result as CommandResult;
5
6
/**
7
 * Result
8
 *
9
 * @package    phpbu
10
 * @subpackage Backup
11
 * @author     Sebastian Feldmann <[email protected]>
12
 * @copyright  Sebastian Feldmann <[email protected]>
13
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
14
 * @link       http://phpbu.de/
15
 * @since      Class available since Release 1.0.0
16
 */
17
class Result
18
{
19
    /**
20
     * Result of executed command.
21
     *
22
     * @var \SebastianFeldmann\Cli\Command\Result
23
     */
24
    private $cmdResult;
25
26
    /**
27
     * Command print safe.
28
     *
29
     * @var string
30
     */
31
    private $printableCmd;
32
33
    /**
34
     * Result constructor.
35
     *
36
     * @param \SebastianFeldmann\Cli\Command\Result $cmdResult
37
     * @param string                                $cmdPrintable
38
     */
39 49
    public function __construct(CommandResult $cmdResult, string $cmdPrintable = '')
40
    {
41 49
        $this->cmdResult    = $cmdResult;
42 49
        $this->printableCmd = $cmdPrintable;
43 49
    }
44
45
    /**
46
     * Get the raw command result.
47
     *
48
     * @return \SebastianFeldmann\Cli\Command\Result
49
     */
50 1
    public function getCommandResult() : CommandResult
51
    {
52 1
        return $this->cmdResult;
53
    }
54
55
    /**
56
     * Return true if command execution was successful.
57
     *
58
     * @return bool
59
     */
60 38
    public function isSuccessful() : bool
61
    {
62 38
        return $this->cmdResult->isSuccessful();
63
    }
64
65
    /**
66
     * Returns the raw cli return code.
67
     *
68
     * @return int
69
     */
70 5
    public function getReturnCode() : int
71
    {
72 5
        return $this->cmdResult->getCode();
73
    }
74
75
    /**
76
     * Return the executed cli command.
77
     *
78
     * @return string
79
     */
80 10
    public function getCmd() : string
81
    {
82 10
        return $this->cmdResult->getCmd();
83
    }
84
85
    /**
86
     * Return the executed cli command.
87
     *
88
     * @return string
89
     */
90 16
    public function getCmdPrintable() : string
91
    {
92 16
        return $this->printableCmd;
93
    }
94
95
    /**
96
     * Return commands output to stdOut.
97
     *
98
     * @return string
99
     */
100 6
    public function getStdOut() : string
101
    {
102 6
        return $this->cmdResult->getStdOut();
103
    }
104
105
    /**
106
     * Return commands error output to stdErr.
107
     *
108
     * @return string
109
     */
110 15
    public function getStdErr() : string
111
    {
112 15
        return $this->cmdResult->getStdErr();
113
    }
114
115
    /**
116
     * Is the output redirected to a file.
117
     *
118
     * @return bool
119
     */
120 2
    public function isOutputRedirected() : bool
121
    {
122 2
        return $this->cmdResult->isOutputRedirected();
123
    }
124
125
    /**
126
     * Return path to the file where the output is redirected to.
127
     *
128
     * @return string
129
     */
130 2
    public function getRedirectPath() : string
131
    {
132 2
        return $this->cmdResult->getRedirectPath();
133
    }
134
135
    /**
136
     * Return cmd output as array.
137
     *
138
     * @return array
139
     */
140 1
    public function getBufferedOutput() : array
141
    {
142 1
        return $this->cmdResult->getStdOutAsArray();
143
    }
144
}
145