Issues (141)

src/ProdLogger.php (1 issue)

Labels
Severity
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 readonly class ProdLogger implements LoggerInterface
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 13 at column 6
Loading history...
14
{
15
    public function __construct(
16
        private 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