AbstractFormat   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Http\Business\Logger\Formatter\Format;
15
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
19
/**
20
 * @author Stanislau Komar <[email protected]>
21
 *
22
 * @codeCoverageIgnore
23
 */
24
abstract class AbstractFormat implements LogFormatterConcreteInterface
25
{
26
    public function format(Request $request, Response|null $response, ?\Throwable $exception, ?string $message = null): string
27
    {
28
        if (!$message) {
29
            return '';
30
        }
31
32
        $var = '{{'.$this->getVarName().'}}';
33
34
        if (!str_contains($message, $var)) {
35
            return $message;
36
        }
37
38
        return str_ireplace(
0 ignored issues
show
Bug Best Practice introduced by
The expression return str_ireplace($var... $exception), $message) could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
39
            $var,
40
            $this->getVarValue($request, $response, $exception),
41
            $message
42
        );
43
    }
44
45
    abstract protected function getVarValue(Request $request, Response|null $response, ?\Throwable $exception): string;
46
47
    abstract protected function getVarName(): string;
48
}
49