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

LineFormatter::format()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
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
}