Passed
Branch releases/1.0-dev (6a4c8c)
by Laurens
03:03
created

Vat::getPercentage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\API\Universal;
6
7
use InvalidArgumentException;
8
9
final class Vat
10
{
11
    private $percentage;
12
13 103
    public function __construct(string $percentage)
14
    {
15 103
        $this->validate($percentage);
16 94
        $this->percentage = $percentage;
17 94
    }
18
19 93
    public function getPercentage(): string
20
    {
21 93
        return $this->percentage;
22
    }
23
24 103
    private function validate(string $percentage): void
25
    {
26 103
        if (!is_numeric($percentage)) {
27 3
            throw new InvalidArgumentException('string is not a valid number');
28
        }
29
30 100 View Code Duplication
        if (ceil((float) $percentage) >= 100 && floor((float) $percentage) >= 100) {
31 4
            throw new InvalidArgumentException('Value to high, must be at most 99.999.');
32
        }
33
34 96 View Code Duplication
        if (floor((float) $percentage) <= 0 && ceil((float) $percentage) != 1) {
35 2
            throw new InvalidArgumentException('Value to low, must be more than 0.');
36
        }
37 94
    }
38
}
39