EnvLine::getKey()   A
last analyzed

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\Lines;
7
8
9
use Enjoys\Dotenv\Parser\Env\Comment;
10
use Enjoys\Dotenv\Parser\Env\Key;
11
use Enjoys\Dotenv\Parser\Env\Value;
12
13
final class EnvLine implements LineInterface
14
{
15 53
    public function __construct(private Key $key, private ?Value $value = null, private ?Comment $comment = null)
16
    {
17 53
    }
18
19
20 9
    public function __toString(): string
21
    {
22 9
        $format = ($this->value === null) ? '%s%s%s' : '%s=%s%s';
23 9
        return sprintf(
24 9
            $format,
25 9
            $this->key->__toString(),
26 9
            $this->value?->__toString() ?? '',
27 9
            $this->comment?->__toString() ?? ''
28 9
        );
29
    }
30
31 45
    public function getKey(): Key
32
    {
33 45
        return $this->key;
34
    }
35
36 43
    public function getValue(): ?Value
37
    {
38 43
        return $this->value;
39
    }
40
41 1
    public function getComment(): ?Comment
42
    {
43 1
        return $this->comment;
44
    }
45
}
46