TelegramFormatter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 31.03 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 1
dl 9
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 9 16 3
A formatBatch() 0 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}