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

Formula   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 21
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A value() 0 3 1
A validate() 0 5 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 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