Completed
Pull Request — master (#2)
by
unknown
03:42
created

ElasticsearchFormatter::formatBatch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
namespace Atrapalo\Monolog\Formatter;
4
5
use DateTime;
6
use Monolog\Formatter\NormalizerFormatter;
7
8
class ElasticsearchFormatter extends NormalizerFormatter
9
{
10
    /**
11
     * @var string
12
     */
13
    private $type;
14
15
    /**
16
     * @var string
17
     */
18
    private $index;
19
20
    public function __construct($index, $type)
21
    {
22
        parent::__construct(DateTime::ISO8601);
23
24
        $this->index = $index;
25
        $this->type = $type;
26
    }
27
28
    public function format(array $record)
29
    {
30
        $record = parent::format($record);
31
32
        return [
33
            'type'      => $this->type,
34
            'index'     => $this->index,
35
            'body'      => $record
36
        ];
37
    }
38
39
    public function formatBatch(array $records)
40
    {
41
        $bulk = ['body' => []];
42
43
        foreach ($records as $record) {
44
            $bulk['body'][] = [
45
                'index' => [
46
                    '_index' => $this->index,
47
                    '_type'  => $this->type,
48
                ]
49
            ];
50
51
            $bulk['body'][] = parent::format($record);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (format() instead of formatBatch()). Are you sure this is correct? If so, you might want to change this to $this->format().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
52
        }
53
54
        return $bulk;
55
    }
56
}