ProdLogger::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource;
6
7
use Override;
8
use Psr\Log\LoggerInterface as PsrLoggerInterface;
9
10
use function in_array;
11
use function sprintf;
12
13
final class ProdLogger implements LoggerInterface
14
{
15
    public function __construct(
16
        private readonly PsrLoggerInterface $logger,
17
    ) {
18
    }
19
20
    #[Override]
21
    public function __invoke(ResourceObject $ro): void
22
    {
23
        $unsafeMethod = ['post', 'put', 'patch', 'delete'];
24
        if (! in_array($ro->uri->method, $unsafeMethod, true)) {
25
            return;
26
        }
27
28
        $msg = sprintf('%s %s %s', $ro->code, $ro->uri->method, (string) $ro->uri);
29
        $this->logger->info($msg);
30
    }
31
}
32