AsciiString   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 41
ccs 11
cts 11
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A asUtf8() 0 3 1
A asCharacters() 0 5 2
A asAscii() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\Lexer\Runtime\Unicode;
6
7
use function array_map;
8
use function str_split;
9
10
/**
11
 * @psalm-immutable
12
 */
13
final class AsciiString implements StringInterface
14
{
15
16
    /**
17
     * @var string
18
     */
19
    private $text;
20
21 5
    public function __construct(string $text)
22
    {
23 5
        $this->text = $text;
24 5
    }
25
26
    /**
27
     * @return array
28
     * @psalm-return array<int, int>
29
     * @psalm-pure
30
     */
31 3
    public function asCharacters(): array
32
    {
33 3
        return '' == $this->text
34 1
            ? []
35 3
            : array_map('ord', str_split($this->text));
36
    }
37
38
    /**
39
     * @return string
40
     * @psalm-pure
41
     */
42 1
    public function asAscii(): string
43
    {
44 1
        return $this->text;
45
    }
46
47
    /**
48
     * @return string
49
     * @psalm-pure
50
     */
51 1
    public function asUtf8(): string
52
    {
53 1
        return $this->text;
54
    }
55
}
56