Completed
Push — master ( e2a90b...0f1023 )
by Sebastian
09:28
created

Result::getOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace phpbu\App\Cli;
3
4
/**
5
 * Runner result
6
 *
7
 * @package    phpbu
8
 * @subpackage Backup
9
 * @author     Sebastian Feldmann <[email protected]>
10
 * @copyright  Sebastian Feldmann <[email protected]>
11
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
12
 * @link       http://phpbu.de/
13
 * @since      Class available since Release 1.0.0
14
 */
15
class Result
16
{
17
    /**
18
     * Command that got executed.
19
     *
20
     * @var string
21
     */
22
    private $cmd;
23
24
    /**
25
     * Result code
26
     *
27
     * @var integer
28
     */
29
    private $code;
30
31
    /**
32
     * Output buffer.
33
     *
34
     * @var array
35
     */
36
    private $buffer;
37
38
    /**
39
     * StdOut
40
     *
41
     * @var string
42
     */
43
    private $stdOut;
44
45
    /**
46
     * StdErr
47
     *
48
     * @var string
49
     */
50
    private $stdErr;
51
52 8
    /**
53
     * Constructor
54 8
     *
55 8
     * @param string  $cmd
56 8
     * @param integer $code
57 8
     * @param string  $stdOut
58
     * @param string  $stdErr
59
     */
60
    public function __construct($cmd, $code, $stdOut = '', $stdErr = '')
61
    {
62
        $this->cmd    = $cmd;
63
        $this->code   = $code;
64 1
        $this->stdOut = $stdOut;
65
        $this->stdErr = $stdErr;
66 1
    }
67
68
    /**
69
     * Cmd getter.
70
     *
71
     * @return string
72
     */
73
    public function getCmd()
74 2
    {
75
        return $this->cmd;
76 2
    }
77
78
    /**
79
     * Code getter.
80
     *
81
     * @return integer
82 2
     */
83
    public function getCode()
84 2
    {
85
        return $this->code;
86
    }
87
88
    /**
89
     * Command executed successful.
90
     */
91
    public function wasSuccessful()
92 1
    {
93
        return $this->code == 0;
94 1
    }
95
96
    /**
97
     * StdOutput getter.
98
     *
99
     * @return mixed array
100
     */
101
    public function getStdOut()
102 2
    {
103
        return $this->stdOut;
104 2
    }
105 2
106 2
    /**
107 2
     * StdError getter.
108
     *
109
     * @return mixed array
110
     */
111
    public function getStdErr()
112
    {
113
        return $this->stdErr;
114
    }
115 2
116
    /**
117 2
     * Return the output ins string format.
118
     *
119
     * @return string
120
     */
121
    public function getStdOutAsArray()
122
    {
123
        if (null === $this->buffer) {
124
            $this->buffer = $this->textToBuffer();
125 1
        }
126
        return $this->buffer;
127 1
    }
128
129
    /**
130
     * Converts the output buffer array into a string.
131
     *
132
     * @return string
133
     */
134
    private function textToBuffer()
135
    {
136
        return explode(PHP_EOL, $this->stdOut);
137
    }
138
139
    /**
140
     * Magic to string method.
141
     *
142
     * @return string
143
     */
144
    public function __toString()
145
    {
146
        return $this->stdOut;
147
    }
148
}
149