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

PropertyFileNotLoadedException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 4
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