Passed
Pull Request — master (#74)
by
unknown
14:45
created

Formula::value()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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