Passed
Pull Request — master (#75)
by
unknown
19:10 queued 04:04
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
class Formula
6
{
7
    public function __construct(private ?string $value, private readonly FormulaEngineInterface $formulaEngine)
8
    {
9
        if (!empty($this->value)) {
10
            $this->value = $this->formulaEngine->normalize($this->value);
0 ignored issues
show
Bug introduced by
The method normalize() does not exist on hiqdev\php\billing\formula\FormulaEngineInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to hiqdev\php\billing\formula\FormulaEngineInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

10
            /** @scrutinizer ignore-call */ 
11
            $this->value = $this->formulaEngine->normalize($this->value);
Loading history...
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