Key   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A __toString() 0 4 1
A getValue() 0 3 1
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 63
    public function __construct(string $value)
16
    {
17 63
        if (!\preg_match('/^([A-Z_])([A-Z_0-9]+)?$/', $value)) {
18 7
            throw new InvalidArgumentException(
19 7
                'The key %s have invalid chars.
20
                The key must be UPPERCASE and have only letters (A-Z) digits (0-9)  and _.
21 7
                And starts with A-Z or _'
22 7
            );
23
        }
24 57
        $this->value = $value;
25
    }
26
27 9
    #[\Override]
28
    public function __toString(): string
29
    {
30 9
        return $this->value;
31
    }
32
33 49
    public function getValue(): string
34
    {
35 49
        return $this->value;
36
    }
37
}
38