GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( d90bd1...097b8b )
by Sebastian
06:19 queued 04:14
created

Hex::toHex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\Color;
4
5
class Hex implements Color
6
{
7
    /** @var string */
8
    protected $red, $green, $blue;
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
9
10
    public function __construct(string $red, string $green, string $blue)
11
    {
12
        Validate::hexChannelValue($red, 'red');
0 ignored issues
show
Unused Code introduced by
The call to Validate::hexChannelValue() has too many arguments starting with 'red'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
13
        Validate::hexChannelValue($green, 'green');
0 ignored issues
show
Unused Code introduced by
The call to Validate::hexChannelValue() has too many arguments starting with 'green'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
14
        Validate::hexChannelValue($blue, 'blue');
0 ignored issues
show
Unused Code introduced by
The call to Validate::hexChannelValue() has too many arguments starting with 'blue'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
15
16
        $this->red = strtolower($red);
17
        $this->green = strtolower($green);
18
        $this->blue = strtolower($blue);
19
    }
20
21
    public static function fromString(string $string)
22
    {
23
        Validate::hexColorString($string);
24
25
        list($red, $green, $blue) = str_split(ltrim($string, '#'), 2);
26
27
        return new static($red, $green, $blue);
28
    }
29
30
    public function red(): string
31
    {
32
        return $this->red;
33
    }
34
35
    public function green(): string
36
    {
37
        return $this->green;
38
    }
39
40
    public function blue(): string
41
    {
42
        return $this->blue;
43
    }
44
45
    public function toHex(): Hex
46
    {
47
        return new self($this->red, $this->green, $this->blue);
48
    }
49
50
    public function toRgb(): Rgb
51
    {
52
        return new Rgb(
53
            Convert::hexChannelToRgbChannel($this->red),
54
            Convert::hexChannelToRgbChannel($this->green),
55
            Convert::hexChannelToRgbChannel($this->blue)
56
        );
57
    }
58
59
    public function toRgba(float $alpha = 1): Rgba
60
    {
61
        return $this->toRgb()->toRgba($alpha);
62
    }
63
64
    public function __toString(): string
65
    {
66
        return "#{$this->red}{$this->green}{$this->blue}";
67
    }
68
}
69