NonAsciiCharacterException::buildMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\Lexer\Runtime\Unicode\Exception;
6
7
use RuntimeException;
8
use Throwable;
9
10
use function dechex;
11
use function strtoupper;
12
13
final class NonAsciiCharacterException extends RuntimeException implements ExceptionInterface
14
{
15
16
    /**
17
     * @var int
18
     */
19
    private $character;
20
21 5
    public function __construct(int $character, Throwable $previous = null)
22
    {
23 5
        $this->character = $character;
24 5
        parent::__construct($this->buildMessage(), 0, $previous);
25 5
    }
26
27 5
    private function buildMessage(): string
28
    {
29 5
        $hexCode = strtoupper(dechex($this->character));
30
31 5
        return "Character 0x{$hexCode} is not in ASCII range";
32
    }
33
34 1
    public function getCharacter(): int
35
    {
36 1
        return $this->character;
37
    }
38
}
39