BulkResponseAggregator::parseErrors()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 22
rs 9.7998
cc 3
nc 3
nop 1
1
<?php namespace Nord\Lumen\Elasticsearch\Documents\Bulk;
2
3
class BulkResponseAggregator
4
{
5
6
    /**
7
     * @var array
8
     */
9
    private $errors = [];
10
11
    /**
12
     * @param array $response
13
     *
14
     * @return BulkResponseAggregator
15
     */
16
    public function addResponse(array $response)
17
    {
18
        $this->parseErrors($response);
19
20
        return $this;
21
    }
22
23
24
    /**
25
     * @return bool
26
     */
27
    public function hasErrors()
28
    {
29
        return count($this->errors) > 0;
30
    }
31
32
33
    /**
34
     * @return array
35
     */
36
    public function getErrors()
37
    {
38
        return $this->errors;
39
    }
40
41
    /**
42
     * @param array $response
43
     */
44
    protected function parseErrors(array $response)
45
    {
46
        $items = array_get($response, 'items', []);
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

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

46
        $items = /** @scrutinizer ignore-deprecated */ array_get($response, 'items', []);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
47
        foreach ($items as $item) {
48
            $item = array_first($item);
0 ignored issues
show
Deprecated Code introduced by
The function array_first() has been deprecated: Arr::first() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

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

48
            $item = /** @scrutinizer ignore-deprecated */ array_first($item);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
49
50
            if (!array_has($item, 'error')) {
0 ignored issues
show
Deprecated Code introduced by
The function array_has() has been deprecated: Arr::has() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

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

50
            if (!/** @scrutinizer ignore-deprecated */ array_has($item, 'error')) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
51
                continue;
52
            }
53
54
            $index = array_get($item, '_index');
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

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

54
            $index = /** @scrutinizer ignore-deprecated */ array_get($item, '_index');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
55
            $type = array_get($item, '_type');
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

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

55
            $type = /** @scrutinizer ignore-deprecated */ array_get($item, '_type');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
56
            $id = array_get($item, '_id');
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

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

56
            $id = /** @scrutinizer ignore-deprecated */ array_get($item, '_id');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
57
58
            $errorType = array_get($item, 'error.type');
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

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

58
            $errorType = /** @scrutinizer ignore-deprecated */ array_get($item, 'error.type');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
59
            $errorReason = array_get($item, 'error.reason');
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

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

59
            $errorReason = /** @scrutinizer ignore-deprecated */ array_get($item, 'error.reason');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
60
61
            $causeType = array_get($item, 'error.caused_by.type');
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

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

61
            $causeType = /** @scrutinizer ignore-deprecated */ array_get($item, 'error.caused_by.type');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
62
            $causeReason = array_get($item, 'error.caused_by.reason');
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

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

62
            $causeReason = /** @scrutinizer ignore-deprecated */ array_get($item, 'error.caused_by.reason');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
63
64
            $this->errors[] = sprintf('Error "%s" reason "%s". Cause "%s" reason "%s". Index "%s", type "%s", id "%s"',
65
                $errorType, $errorReason, $causeType, $causeReason, $index, $type, $id);
66
        }
67
    }
68
69
70
    /**
71
     *
72
     */
73
    public function reset()
74
    {
75
        $this->errors = [];
76
    }
77
}
78