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

PropertyFileNotLoadedException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 16
c 1
b 0
f 0
dl 0
loc 40
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A buildMessage() 0 9 2
A getPropertyName() 0 3 1
A getPropertyFile() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\UniLex\RegExp\Exception;
6
7
use RuntimeException;
8
use Throwable;
9
10
final class PropertyFileNotLoadedException extends RuntimeException implements ExceptionInterface
11
{
12
13
    private $propertyName;
14
15
    private $propertyFile;
16
17
    private $errorMessage;
18
19
    public function __construct(
20
        string $propertyName,
21
        string $propertyFile,
22
        ?string $errorMessage,
23
        Throwable $previous = null
24
    ) {
25
        $this->propertyName = $propertyName;
26
        $this->propertyFile = $propertyFile;
27
        $this->errorMessage = $errorMessage;
28
        parent::__construct($this->buildMessage(), 0, $previous);
29
    }
30
31
    private function buildMessage(): string
32
    {
33
        $message =
34
            "Failed to load range set for Unicode property '{$this->propertyName}' " .
35
            "from file {$this->propertyFile}";
36
37
        return isset($this->errorMessage)
38
            ? "{$message}:\n{$this->errorMessage}"
39
            : $message;
40
    }
41
42
    public function getPropertyName(): string
43
    {
44
        return $this->propertyName;
45
    }
46
47
    public function getPropertyFile(): string
48
    {
49
        return $this->propertyFile;
50
    }
51
}
52