ClassExtractorException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 8
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Exception;
6
7
use JetBrains\PhpStorm\Immutable;
8
use JetBrains\PhpStorm\Pure;
9
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
10
use Throwable;
11
12
#[Immutable]
13 2
final class ClassExtractorException extends \RuntimeException
14 2
{
15
    #[Pure]
16
    public function __construct(
17
        private readonly string $property,
18
        string $message,
19
        int $code = 0,
20 2
        ?Throwable $previous = null
21
    ) {
22
        parent::__construct($message, $code, $previous);
23 1
    }
24
25
    #[Pure]
26 1
    public static function fromDiscriminatorMapWhenParameterIsNull(DiscriminatorMap $discriminatorMap): self
27 1
    {
28
        $property = $discriminatorMap->getTypeProperty();
29 1
        $message = sprintf('%s cannot be null or empty', $property);
30
31
        return new self($property, $message);
32 1
    }
33
34
    #[Pure]
35 1
    public static function fromDiscriminatorMapWhenParameterInvalid(DiscriminatorMap $discriminatorMap): self
36 1
    {
37 1
        $property = $discriminatorMap->getTypeProperty();
38
        $expectedValues = array_keys($discriminatorMap->getMapping());
39 1
        $message = sprintf('%s can only be %s', $property, implode(', ', $expectedValues));
40
41
        return new self($message, $property);
42 1
    }
43
44 1
    public function getProperty(): string
45
    {
46
        return $this->property;
47
    }
48
}
49