Completed
Push — master ( a796d5...6aa47e )
by Ievgen
02:22
created

functions.php ➔ error()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 2
rs 9.4285
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 $appendParams = [])
9
{
10 3
    return ['type' => RESPONSE_TYPE_OK, 'appendParams' => $appendParams];
11
}
12
13
/**
14
 * @param mixed $appendError Can accept Array of string or a single String 
15
 * and convert it to Array of strings
16
 */
17
function error($appendError)
18
{
19 1
    $appendError = (is_string($appendError)) ? [$appendError] : $appendError;
20 1
    return ['type' => RESPONSE_TYPE_ERROR, 'appendError' => $appendError];
21
}
22
23
function isOk($type)
24
{
25 3
    return $type == RESPONSE_TYPE_OK;
26
}
27
28
function isError($type)
29
{
30 3
    return $type == RESPONSE_TYPE_ERROR;
31
}
32
33
function isValidResponse($response)
34
{
35 5
    return is_array($response) && isset($response['type']);
36
}
37