InvalidPropertyRangeSetException   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 62
ccs 0
cts 19
cp 0
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPropertyName() 0 3 1
A getRangeSet() 0 3 1
A buildMessage() 0 10 2
A __construct() 0 6 1
A getPropertyFile() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\UCD\Exception;
6
7
use Remorhaz\IntRangeSets\RangeSetInterface;
8
use Throwable;
9
use UnexpectedValueException;
10
11
use function get_class;
12
use function gettype;
13
use function is_object;
14
15
final class InvalidPropertyRangeSetException extends UnexpectedValueException implements ExceptionInterface
16
{
17
18
    /**
19
     * @var string
20
     */
21
    private $propertyName;
22
23
    /**
24
     * @var string
25
     */
26
    private $propertyFile;
27
28
    /**
29
     * @var mixed
30
     */
31
    private $rangeSet;
32
33
    /**
34
     * InvalidPropertyRangeSetException constructor.
35
     *
36
     * @param string         $propertyName
37
     * @param string         $propertyFile
38
     * @param mixed          $rangeSet
39
     * @param Throwable|null $previous
40
     */
41
    public function __construct(string $propertyName, string $propertyFile, $rangeSet, Throwable $previous = null)
42
    {
43
        $this->propertyName = $propertyName;
44
        $this->propertyFile = $propertyFile;
45
        $this->rangeSet = $rangeSet;
46
        parent::__construct($this->buildMessage(), 0, $previous);
47
    }
48
49
    private function buildMessage(): string
50
    {
51
        $actualType = is_object($this->rangeSet)
52
            ? get_class($this->rangeSet)
53
            : gettype($this->rangeSet);
54
        $expectedType = RangeSetInterface::class;
55
56
        return
57
            "Invalid range set loaded from {$this->propertyFile} for Unicode property '{$this->propertyName}':\n" .
58
            "{$actualType} instead of {$expectedType}";
59
    }
60
61
    public function getPropertyName(): string
62
    {
63
        return $this->propertyName;
64
    }
65
66
    public function getPropertyFile(): string
67
    {
68
        return $this->propertyFile;
69
    }
70
71
    /**
72
     * @return mixed
73
     */
74
    public function getRangeSet()
75
    {
76
        return $this->rangeSet;
77
    }
78
}
79