Passed
Push — master ( d8e937...c675bb )
by Edward
10:57
created

AsciiString::asUtf8()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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