Bulk::hasError()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
4
namespace Manticoresearch\Response;
5
6
use Manticoresearch\Response;
7
8
class Bulk extends Response
9
{
10
11
    /*
12
     * Check whenever response has error
13
     * @return bool
14
     */
15
    public function hasError()
16
    {
17
        $response = $this->getResponse();
18
        foreach ($response as $r) {
19
            if (isset($r['error']) && $r['error'] !== '') {
20
                return true;
21
            }
22
        }
23
        return false;
24
    }
25
26
    /*
27
     * Return error
28
     * @return false|string
29
     */
30
    public function getError()
31
    {
32
        $response = $this->getResponse();
33
        $errors = "";
34
        foreach ($response as $r) {
35
            if (isset($r['error']) && $r['error'] !== '') {
36
                $errors .= json_encode($r['error'], true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type integer expected by parameter $flags of json_encode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
                $errors .= json_encode($r['error'], /** @scrutinizer ignore-type */ true);
Loading history...
37
            }
38
        }
39
        return $errors;
40
    }
41
}
42