RendererEntry   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 10
c 3
b 0
f 0
dl 0
loc 37
ccs 13
cts 13
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A log() 0 3 1
A matches() 0 13 4
A getLogLevel() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Conia\Error;
6
7
use Throwable;
8
9
class RendererEntry
10
{
11
    private string|int|null $logLevel = null;
12
13
    /**
14
     * @param class-string<Throwable>[] $exceptions
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<Throwable>[] at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<Throwable>[].
Loading history...
15
     */
16 10
    public function __construct(
17
        public readonly array $exceptions,
18
        public readonly Renderer $renderer
19
    ) {
20 10
    }
21
22 9
    public function matches(Throwable $exception): bool
23
    {
24 9
        foreach ($this->exceptions as $exceptionEntry) {
25 9
            if ($exception::class === $exceptionEntry) {
26 5
                return true;
27
            }
28
29 4
            if (is_subclass_of($exception::class, $exceptionEntry)) {
30 3
                return true;
31
            }
32
        }
33
34 1
        return false;
35
    }
36
37
    /** @psalm-api */
38 1
    public function log(string|int $logLevel): void
39
    {
40 1
        $this->logLevel = $logLevel;
41
    }
42
43 8
    public function getLogLevel(): string|int|null
44
    {
45 8
        return $this->logLevel;
46
    }
47
}
48