TelegramFormatter::formatBatch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
/**
3
 * This file is a part of TelegramHandler project.
4
 * @author Amin Alizade < [email protected] >
5
 */
6
7
namespace TelegramHandler;
8
9
10
use Monolog\Formatter\FormatterInterface;
11
use Symfony\Component\Yaml\Yaml;
12
13
class TelegramFormatter implements FormatterInterface
14
{
15
    public function format(array $record)
16
    {
17
        $message = " <i>[{$record['level_name']}]</i>" . '<i>[' . $record['channel'] . ']</i>' . " at " . $record['datetime']->format("Y-m-d H:i:s") . PHP_EOL;
18
        $message .= $record['message'] . PHP_EOL;
19
        $message .= PHP_EOL;
20 View Code Duplication
        if ($record['context']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
            $message .= "[context]" . PHP_EOL;
22
            $message .= Yaml::dump($record['context']);
23
            $message .= PHP_EOL;
24
        }
25 View Code Duplication
        if ($record['extra']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
            $message .= "[extra]" . PHP_EOL;
27
            $message .= Yaml::dump($record['extra']);
28
        }
29
        return $message;
30
    }
31
32
    public function formatBatch(array $records)
33
    {
34
        $message = '';
35
        foreach ($records as $record) {
36
            $message .= $this->format($record);
37
        }
38
        return $message;
39
    }
40
41
}