RepositoryLogger::log()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 15
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository;
6
7
use Override;
8
use Stringable;
9
10
use function implode;
11
use function is_array;
12
use function vsprintf;
13
14
use const PHP_EOL;
15
16
final class RepositoryLogger implements RepositoryLoggerInterface, Stringable
17
{
18
    /** @var list<string> */
0 ignored issues
show
Bug introduced by
The type BEAR\QueryRepository\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
    private array $logs = [];
20
21
    /**
22
     * {@inheritDoc}
23
     */
24
    #[Override]
25
    public function log(string $template, ...$values): void
26
    {
27
        /** @var bool|float|int|string|list<string>|null $value */
28
        foreach ($values as &$value) {
29
            if (is_array($value)) {
30
                $value = $value !== [] ? implode(' ', $value) : '';
31
            }
32
        }
33
34
        unset($value);
35
        /** @var list<string> $values */
36
        $msg = vsprintf($template, $values);
0 ignored issues
show
Bug introduced by
$values of type BEAR\QueryRepository\list is incompatible with the type array expected by parameter $values of vsprintf(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        $msg = vsprintf($template, /** @scrutinizer ignore-type */ $values);
Loading history...
37
38
        $this->logs[] = $msg;
39
    }
40
41
    #[Override]
42
    public function __toString(): string
43
    {
44
        return implode(PHP_EOL, $this->logs);
45
    }
46
}
47