Passed
Push — 1.x ( 77e7f6...966118 )
by Adrian
02:40 queued 12s
created

Bulk::hasError()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
4
namespace Manticoresearch\Response;
5
6
7
use Manticoresearch\Response;
8
9
class Bulk extends Response
10
{
11
12
    /*
13
     * Check whenever response has error
14
     * @return bool
15
     */
16
    public function hasError()
17
    {
18
        $response = $this->getResponse();
19
        foreach ($response as $r) {
20
            if (isset($r['error']) && $r['error'] !== '') {
21
                return true;
22
            }
23
        }
24
        return false;
25
    }
26
27
    /*
28
     * Return error
29
     * @return false|string
30
     */
31
    public function getError()
32
    {
33
        $response = $this->getResponse();
34
        $errors = "";
35
        foreach ($response as $r) {
36
            if (isset($r['error']) && $r['error'] !== '') {
37
                $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 $options 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

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