StatusFormat::getVarValue()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 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
class StatusFormat extends AbstractFormat
23
{
24 6
    protected function getVarValue(Request $request, Response|null $response, ?\Throwable $exception): string
25
    {
26 6
        if (null !== $response) {
27 3
            return (string) $response->getStatusCode();
28
        }
29
30 3
        if ($exception instanceof \Throwable) {
31 2
            return (string) $exception->getCode();
32
        }
33
34 1
        return '500';
35
    }
36
37 6
    protected function getVarName(): string
38
    {
39 6
        return 'status';
40
    }
41
}
42