Passed
Pull Request — master (#6)
by Laurens
01:54
created

Hex   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 21.95 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 9
loc 41
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

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\ApplePassbook\Style\Color;
6
7
use LauLamanApps\ApplePassbook\Exception\InvalidArgumentException;
8
use LauLamanApps\ApplePassbook\Style\Color;
9
10
class Hex implements Color
11
{
12
    private string $hex;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
13
14 22
    public function __construct(string $hex)
15
    {
16 22
        if (strlen($hex) !== 6 || !ctype_xdigit($hex)) {
17 3
            throw new InvalidArgumentException('Please specify a valid hex. (without the #)');
18
        }
19
20 19
        $this->hex = $hex;
21 19
    }
22
23 19
    public function toString(): string
24
    {
25 19
        return sprintf('#%s', $this->hex);
26
    }
27
}
28