@@ -11,20 +11,20 @@ class RunnerResult
1111 /** @var int */
1212 private $ exitCode ;
1313
14- /** @var string[] */
14+ /** @var string|string [] */
1515 private $ output ;
1616
17- /** @var string[] */
17+ /** @var string|string [] */
1818 private $ errorOutput ;
1919
2020
2121 /**
2222 * @param string $command
2323 * @param int $exitCode
24- * @param string[] $output
25- * @param string[] $errorOutput
24+ * @param string|string [] $output
25+ * @param string|string [] $errorOutput
2626 */
27- public function __construct ($ command , $ exitCode , array $ output , array $ errorOutput )
27+ public function __construct ($ command , $ exitCode , $ output , $ errorOutput )
2828 {
2929 $ this ->command = (string ) $ command ;
3030 $ this ->exitCode = (int ) $ exitCode ;
@@ -65,6 +65,10 @@ public function getExitCode()
6565 */
6666 public function getOutput ()
6767 {
68+ if (is_string ($ this ->output )) {
69+ return $ this ->splitOutput ($ this ->output );
70+ }
71+
6872 return $ this ->output ;
6973 }
7074
@@ -74,6 +78,10 @@ public function getOutput()
7478 */
7579 public function getOutputAsString ()
7680 {
81+ if (is_string ($ this ->output )) {
82+ return $ this ->output ;
83+ }
84+
7785 return implode ("\n" , $ this ->output );
7886 }
7987
@@ -83,7 +91,8 @@ public function getOutputAsString()
8391 */
8492 public function getOutputLastLine ()
8593 {
86- $ lastLine = end ($ this ->output );
94+ $ output = $ this ->getOutput ();
95+ $ lastLine = end ($ output );
8796 return is_string ($ lastLine ) ? $ lastLine : NULL ;
8897 }
8998
@@ -93,6 +102,10 @@ public function getOutputLastLine()
93102 */
94103 public function hasOutput ()
95104 {
105+ if (is_string ($ this ->output )) {
106+ return trim ($ this ->output ) !== '' ;
107+ }
108+
96109 return !empty ($ this ->output );
97110 }
98111
@@ -102,15 +115,36 @@ public function hasOutput()
102115 */
103116 public function getErrorOutput ()
104117 {
118+ if (is_string ($ this ->errorOutput )) {
119+ return $ this ->splitOutput ($ this ->errorOutput );
120+ }
121+
105122 return $ this ->errorOutput ;
106123 }
107124
108125
126+ /**
127+ * @return string
128+ */
129+ public function getErrorOutputAsString ()
130+ {
131+ if (is_string ($ this ->errorOutput )) {
132+ return $ this ->errorOutput ;
133+ }
134+
135+ return implode ("\n" , $ this ->errorOutput );
136+ }
137+
138+
109139 /**
110140 * @return bool
111141 */
112142 public function hasErrorOutput ()
113143 {
144+ if (is_string ($ this ->errorOutput )) {
145+ return trim ($ this ->errorOutput ) !== '' ;
146+ }
147+
114148 return !empty ($ this ->errorOutput );
115149 }
116150
@@ -127,4 +161,21 @@ public function toText()
127161 . implode ("\n" , $ this ->getErrorOutput ()) . "\n\n"
128162 . '=> ' . $ this ->getExitCode () . "\n\n" ;
129163 }
164+
165+
166+ /**
167+ * @param string $output
168+ * @return string[]
169+ */
170+ private function splitOutput ($ output )
171+ {
172+ $ output = str_replace (["\r\n" , "\r" ], "\n" , $ output );
173+ $ output = rtrim ($ output , "\n" );
174+
175+ if ($ output === '' ) {
176+ return [];
177+ }
178+
179+ return explode ("\n" , $ output );
180+ }
130181 }
0 commit comments