Passed
Push — master ( 26669d...eddd64 )
by
unknown
04:41
created

LineTableSyncFormatter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 16
c 1
b 0
f 0
dl 0
loc 35
ccs 14
cts 16
cp 0.875
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A format() 0 22 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Umbrellio\TableSync\Monolog\Formatter;
6
7
class LineTableSyncFormatter extends TableSyncFormatter
8
{
9
    private $format = '[%datetime%] %message% %routing% %model% %event%';
10
11 1
    public function __construct(?string $format = null)
12
    {
13 1
        parent::__construct();
14
15 1
        if ($format !== null) {
16
            $this->format = $format;
17
        }
18
    }
19
20 1
    public function format(array $record): string
21
    {
22 1
        $vars = parent::format($record);
23
24 1
        $output = $this->format . PHP_EOL;
25
26 1
        foreach ($vars as $var => $value) {
27 1
            if (is_array($value)) {
28 1
                $output = str_replace("%{$var}%", json_encode($value), $output);
29 1
                continue;
30
            }
31
32 1
            if (strpos($output, "%{$var}%") !== false) {
33 1
                $output = str_replace("%{$var}%", $value, $output);
34
            }
35
        }
36
37 1
        if ($vars['exception'] !== null) {
38
            $output .= (string) $vars['exception'] . PHP_EOL;
39
        }
40
41 1
        return $output;
42
    }
43
}
44