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

Vat   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 30
Duplicated Lines 20 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 6
loc 30
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getPercentage() 0 4 1
A validate() 6 14 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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