Test Failed
Pull Request — master (#6)
by Laurens
01:35
created

Hex::__construct()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 18

Duplication

Lines 9
Ratio 50 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
dl 9
loc 18
ccs 10
cts 10
cp 1
rs 9.3554
c 0
b 0
f 0
cc 5
nc 5
nop 1
crap 5
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
    public function __construct(string $hex)
15
    {
16
        if (strlen($hex) !== 6 || !ctype_xdigit($hex)) {
17
            throw new InvalidArgumentException('Please specify a valid hex. (without the #)');
18
        }
19
20
        $this->hex = $hex;
21
    }
22
23
    public function toString(): string
24
    {
25
        return sprintf('#%s', $this->hex);
26
    }
27
}
28