Passed
Push — master ( 4b3d26...06dcf5 )
by Enjoys
12:36 queued 13s
created

Key::__toString()   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 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
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
6
namespace Enjoys\Dotenv\Parser\Env;
7
8
9
use Enjoys\Dotenv\Exception\InvalidArgumentException;
10
11
final class Key implements \Stringable
12
{
13
    private string $value;
14
15 62
    public function __construct(string $value)
16
    {
17 62
        if (!\preg_match('/^([A-Z_])([A-Z_0-9]+)?$/', $value)) {
18 7
            throw new InvalidArgumentException(
19
                'The key %s have invalid chars.
20
                The key must be UPPERCASE and have only letters (A-Z) digits (0-9)  and _.
21
                And starts with A-Z or _'
22
            );
23
        }
24 56
        $this->value = $value;
25
    }
26
27 10
    public function __toString(): string
28
    {
29 10
        return $this->value;
30
    }
31
32 47
    public function getValue(): string
33
    {
34 47
        return $this->value;
35
    }
36
}
37