Value::getValue()   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
namespace Enjoys\Dotenv\Parser\Env;
6
7
final class Value implements \Stringable
8
{
9
    private string $value;
10
11
12 50
    public function __construct(
13
        string $value,
14
        private ?string $quote = null
15
    ) {
16 50
        $this->value = $this->handleValue($value);
17
    }
18
19 50
    private function handleValue(string $value): string
20
    {
21 50
        if (preg_match('/#+/', $value)) {
22 6
            $this->quote = '"';
23
        }
24 50
        if (preg_match('/^["\']+/', $value)) {
25 24
            $this->quote = null;
26
        }
27 50
        return $this->quote !== null ? sprintf('%2$s%1$s%2$s', $value, $this->quote) : $value;
28
    }
29
30 5
    #[\Override]
31
    public function __toString(): string
32
    {
33 5
        return $this->value;
34
    }
35
36 44
    public function getValue(): string
37
    {
38 44
        return $this->value;
39
    }
40
41
}
42