functions.php ➔ isValidResponse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 2
nc 3
nop 1
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace einfach\operation\response;
4
5
const RESPONSE_TYPE_OK = 'ok_step_response';
6
const RESPONSE_TYPE_ERROR = 'error_step_response';
7
8
function ok(array $params, array $appendParams = [])
9
{
10
    return [
11 12
        'type' => RESPONSE_TYPE_OK,
12 12
        'params' => $params,
13 12
        'appendParams' => $appendParams
14
        ];
15
}
16
17
/**
18
 * @param mixed $appendError Can accept Array of string or a single String
19
 *                           and convert it to Array of strings
20
 */
21
function error(array $params, $appendError = [])
22
{
23 11
    $appendError = (is_string($appendError)) ? [$appendError] : $appendError;
24
    return [
25 11
        'type' => RESPONSE_TYPE_ERROR,
26 11
        'params' => $params,
27 11
        'appendError' => $appendError
28
        ];
29
}
30
31
function isOk($stepResult)
32
{
33 21
    return isValidResponse($stepResult) && $stepResult['type'] == RESPONSE_TYPE_OK;
34
}
35
36
function isError($stepResult)
37
{
38 18
    return isValidResponse($stepResult) && $stepResult['type'] == RESPONSE_TYPE_ERROR;
39
}
40
41
function isValidResponse($response)
42
{
43 25
    return is_array($response) && isset($response['params']) && isset($response['type']);
44
}
45