Passed
Pull Request — master (#75)
by
unknown
13:27
created

Formula::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 2
nc 2
nop 2
1
<?php declare(strict_types=1);
2
3
namespace hiqdev\php\billing\formula;
4
5
class Formula
6
{
7
    public function __construct(private ?string $value, private readonly FormulaEngine $formulaEngine)
8
    {
9
        if (!empty($this->value)) {
10
            $this->value = $this->formulaEngine->normalize($this->value);
11
            $this->validate($this->value);
12
        }
13
    }
14
15
    private function validate(string $value): void
16
    {
17
        $error = $this->formulaEngine->validate($value);
18
        if ($error !== null) {
19
            throw new FormulaEngineException($error);
20
        }
21
    }
22
23
    public function value(): ?string
24
    {
25
        return $this->value;
26
    }
27
}
28