Completed
Push — log-level ( 45be4f...1ddb1b )
by Akihito
03:47
created

ProdLogger::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource;
6
7
use function in_array;
8
use function sprintf;
9
use Psr\Log\LoggerInterface as PsrLoggerInterface;
10
11
final class ProdLogger implements LoggerInterface
12
{
13
    /**
14
     * @var PsrLoggerInterface
15
     */
16
    private $logger;
17
18
    public function __construct(PsrLoggerInterface $logger)
19
    {
20
        $this->logger = $logger;
21
    }
22
23
    public function __invoke(ResourceObject $ro) : void
24
    {
25
        $unsafeMethod = ['post', 'put', 'patch', 'delete'];
26
        if (! in_array($ro->uri->method, $unsafeMethod, true)) {
27
            return;
28
        }
29
        $msg = sprintf('%s %s %s', $ro->code, $ro->uri->method, (string) $ro->uri);
30
        $this->logger->info('request', $msg);
0 ignored issues
show
Documentation introduced by
$msg is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
    }
32
}
33
34