Passed
Push — main ( 414146...ad9f42 )
by Fractal
02:31
created

ClassExtractorException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 30
rs 10
ccs 14
cts 15
cp 0.9333
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromDiscriminatorMapWhenParameterInvalid() 0 8 1
A __construct() 0 4 1
A getProperty() 0 3 1
A fromDiscriminatorMapWhenParameterIsNull() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Exception;
6
7
use JetBrains\PhpStorm\Pure;
8
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
9
use Throwable;
10
11
final class ClassExtractorException extends \RuntimeException
12
{
13 2
    #[Pure]
14
    public function __construct(private string $property, string $message, int $code = 0, ?Throwable $previous = null)
15
    {
16 2
        parent::__construct($message, $code, $previous);
17 2
    }
18
19 1
    #[Pure]
20
    public static function fromDiscriminatorMapWhenParameterIsNull(DiscriminatorMap $discriminatorMap): self
21
    {
22 1
        $property = $discriminatorMap->getTypeProperty();
23 1
        $message = sprintf('%s cannot be null or empty', $property);
24
25 1
        return new self($property, $message);
26
    }
27
28 1
    #[Pure]
29
    public static function fromDiscriminatorMapWhenParameterInvalid(DiscriminatorMap $discriminatorMap): self
30
    {
31 1
        $property = $discriminatorMap->getTypeProperty();
32 1
        $expectedValues = array_keys($discriminatorMap->getMapping());
33 1
        $message = sprintf('%s can only be %s', $property, implode(', ', $expectedValues));
34
35 1
        return new self($message, $property);
36
    }
37
38 1
    public function getProperty(): string
39
    {
40 1
        return $this->property;
41
    }
42
}
43