ExceptionWithNewLineProcessor   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 9
dl 0
loc 18
rs 10
c 1
b 0
f 0
ccs 9
cts 9
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Common\Logger\Processor;
6
7
use function str_replace;
8
use function strpos;
9
10
use const PHP_EOL;
11
12
final class ExceptionWithNewLineProcessor
13
{
14
    private const EXCEPTION_PLACEHOLDER = '{e}';
15
16 5
    public function __invoke(array $record): array
17
    {
18 5
        $message = $record['message'];
19 5
        $messageHasExceptionPlaceholder = strpos($message, self::EXCEPTION_PLACEHOLDER) !== false;
20
21 5
        if ($messageHasExceptionPlaceholder) {
22 3
            $record['message'] = str_replace(
23 3
                self::EXCEPTION_PLACEHOLDER,
24 3
                PHP_EOL . self::EXCEPTION_PLACEHOLDER,
25 3
                $message,
26
            );
27
        }
28
29 5
        return $record;
30
    }
31
}
32