Skip to content

Commit 8bce332

Browse files
committed
feat(cli): fix warnings in parser.php
1 parent da9af8c commit 8bce332

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

templates/cli/src/Client.php.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,13 @@ class Client
261261
switch (substr($responseType, 0, strpos($responseType, ';'))) {
262262
case 'application/json':
263263
$responseBody = json_decode($responseBody, true);
264-
break;
264+
break;
265+
default:
266+
$responseBody = [
267+
"responseCode" => $responseStatus,
268+
"message" => $responseBody
269+
];
270+
break;
265271
}
266272
267273
if ((curl_errno($ch)/* || 200 != $responseStatus*/)) {

templates/cli/src/Parser.php.twig

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,29 @@ class Parser {
3737
protected const headerColor = self::colors[2];
3838
3939
/**
40-
* Parse the response from the server
40+
* Parse the response body from the server
4141
*
42-
* @param array $response
42+
* @param $responseBody
4343
* @return void
4444
*/
45-
public function parseResponse($response)
45+
public function parseResponse($responseBody)
4646
{
47-
foreach ($response as $key => $value) {
48-
if (is_array($value) && count($value) !== 0 ) {
49-
$this->drawKeyValue($key, '');
50-
$this->drawTable($value, self::headerColor, self::tableColor);
51-
}
52-
else {
53-
$this->drawKeyValue($key, $value);
47+
if(is_array($responseBody)) {
48+
foreach ($responseBody as $key => $value) {
49+
if (is_array($value) && count($value) !== 0 ) {
50+
$this->drawKeyValue($key, '');
51+
$this->drawTable($value, self::headerColor, self::tableColor);
52+
}
53+
else {
54+
$this->drawKeyValue($key, $value);
55+
}
5456
}
57+
} else {
58+
printf($responseBody);
5559
}
5660
}
5761
62+
5863
/**
5964
* Print a key value pair
6065
*
@@ -126,6 +131,13 @@ class Parser {
126131
$table->display();
127132
}
128133
134+
135+
/**
136+
* Formats an associative array of commands and descriptions using a 80 column mask
137+
*
138+
* @param array $arr
139+
* @return void
140+
*/
129141
public function formatArray(array $arr) {
130142
$descriptionColumnLimit = 60;
131143
$commandNameColumnLimit = 20;

0 commit comments

Comments
 (0)