PropertyFileNotLoadedException::buildMessage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\UCD\Exception;
6
7
use RuntimeException;
8
use Throwable;
9
10
final class PropertyFileNotLoadedException extends RuntimeException implements ExceptionInterface
11
{
12
13
    /**
14
     * @var string
15
     */
16
    private $propertyName;
17
18
    /**
19
     * @var string
20
     */
21
    private $propertyFile;
22
23
    /**
24
     * @var string|null
25
     */
26
    private $errorMessage;
27
28
    public function __construct(
29
        string $propertyName,
30
        string $propertyFile,
31
        ?string $errorMessage,
32
        Throwable $previous = null
33
    ) {
34
        $this->propertyName = $propertyName;
35
        $this->propertyFile = $propertyFile;
36
        $this->errorMessage = $errorMessage;
37
        parent::__construct($this->buildMessage(), 0, $previous);
38
    }
39
40
    private function buildMessage(): string
41
    {
42
        $message =
43
            "Failed to load range set for Unicode property '{$this->propertyName}' " .
44
            "from file {$this->propertyFile}";
45
46
        return isset($this->errorMessage)
47
            ? "{$message}:\n{$this->errorMessage}"
48
            : $message;
49
    }
50
51
    public function getPropertyName(): string
52
    {
53
        return $this->propertyName;
54
    }
55
56
    public function getPropertyFile(): string
57
    {
58
        return $this->propertyFile;
59
    }
60
61
    public function getErrorMessage(): ?string
62
    {
63
        return $this->errorMessage;
64
    }
65
}
66