LineTableSyncFormatter::format()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.0144

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 22
ccs 11
cts 12
cp 0.9167
rs 9.6111
cc 5
nc 8
nop 1
crap 5.0144
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