RepositoryLogger   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 29
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A log() 0 4 1
A reset() 0 4 1
A __toString() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository;
6
7
use Override;
8
use Stringable;
9
10
use function array_map;
11
use function implode;
12
use function json_encode;
13
14
use const JSON_UNESCAPED_SLASHES;
15
use const PHP_EOL;
16
17
final class RepositoryLogger implements RepositoryLoggerInterface, Stringable
18
{
19
    /** @var list<array<string, mixed>> */
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...
20
    private array $logs = [];
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    #[Override]
26
    public function log(string $operation, array $context = []): void
27
    {
28
        $this->logs[] = ['op' => $operation, ...$context];
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    #[Override]
35
    public function reset(): void
36
    {
37
        $this->logs = [];
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type BEAR\QueryRepository\list of property $logs.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
    }
39
40
    #[Override]
41
    public function __toString(): string
42
    {
43
        return implode(PHP_EOL, array_map(
44
            static fn (array $log): string => (string) json_encode($log, JSON_UNESCAPED_SLASHES),
45
            $this->logs,
46
        ));
47
    }
48
}
49