RendererEntry::getLogLevel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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