Passed
Push — master ( afa595...3d30f2 )
by Marcel
08:58
created

LineFormatter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 8 3
A formatBatch() 0 6 2
1
<?php
2
3
namespace App\Monolog;
4
5
use Monolog\Formatter\FormatterInterface;
6
7
class LineFormatter implements FormatterInterface {
8
9
    /**
10
     * @inheritDoc
11
     */
12
    public function format(array $record): mixed {
13
        $line = $record['message'];
14
15
        foreach($record['context'] as $key => $value) {
16
            $line = str_replace('{' . $key . '}', is_scalar($value) ? $value : json_encode($value, JSON_THROW_ON_ERROR), $line);
17
        }
18
19
        return $line;
20
    }
21
22
    /**
23
     * @inheritDoc
24
     */
25
    public function formatBatch(array $records): array {
26
        foreach($records as $key => $record) {
27
            $records[$key] = $this->format($record);
28
        }
29
30
        return $records;
31
    }
32
}