Passed
Push — master ( eff209...0e7332 )
by Edward
05:02
created

InvalidPropertyRangeSetException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 17
c 1
b 0
f 0
dl 0
loc 42
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPropertyName() 0 3 1
A getRangeSet() 0 3 1
A buildMessage() 0 10 2
A getPropertyFile() 0 3 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\UniLex\RegExp\Exception;
6
7
use Remorhaz\UniLex\RegExp\FSM\RangeSet;
8
use Throwable;
9
use UnexpectedValueException;
10
use function get_class;
11
use function gettype;
12
use function is_object;
13
14
final class InvalidPropertyRangeSetException extends UnexpectedValueException implements ExceptionInterface
15
{
16
17
    private $propertyName;
18
19
    private $propertyFile;
20
21
    private $rangeSet;
22
23
    public function __construct(string $propertyName, string $propertyFile, $rangeSet, Throwable $previous = null)
24
    {
25
        $this->propertyName = $propertyName;
26
        $this->propertyFile = $propertyFile;
27
        $this->rangeSet = $rangeSet;
28
        parent::__construct($this->buildMessage(), 0, $previous);
29
    }
30
31
    private function buildMessage(): string
32
    {
33
        $actualType = is_object($this->rangeSet)
34
            ? get_class($this->rangeSet)
35
            : gettype($this->rangeSet);
36
        $expectedType = RangeSet::class;
37
38
        return
39
            "Invalid range set loaded from {$this->propertyFile} for Unicode property '{$this->propertyName}':\n" .
40
            "{$actualType} instead of {$expectedType}";
41
    }
42
43
    public function getPropertyName(): string
44
    {
45
        return $this->propertyName;
46
    }
47
48
    public function getPropertyFile(): string
49
    {
50
        return $this->propertyFile;
51
    }
52
53
    public function getRangeSet()
54
    {
55
        return $this->rangeSet;
56
    }
57
}
58