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 ( 3a5612...a86930 )
by Sebastian
17s queued 13s
created

Hex::toHsl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.9332
cc 1
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;
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
        [$red, $green, $blue] = str_split(ltrim($string, '#'), 2);
0 ignored issues
show
Bug introduced by
The variable $red does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $green does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $blue does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
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(): self
46
    {
47
        return new self($this->red, $this->green, $this->blue);
48
    }
49
50
    public function toHsl(): Hsl
51
    {
52
        [$hue, $saturation, $lightness] = Convert::rgbValueToHsl(
0 ignored issues
show
Bug introduced by
The variable $hue does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $saturation does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $lightness does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
53
            Convert::hexChannelToRgbChannel($this->red),
54
            Convert::hexChannelToRgbChannel($this->green),
55
            Convert::hexChannelToRgbChannel($this->blue)
56
        );
57
58
        return new Hsl($hue, $saturation, $lightness);
59
    }
60
61
    public function toHsla(float $alpha = 1): Hsla
62
    {
63
        [$hue, $saturation, $lightness] = Convert::rgbValueToHsl(
0 ignored issues
show
Bug introduced by
The variable $hue does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $saturation does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $lightness does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
64
            Convert::hexChannelToRgbChannel($this->red),
65
            Convert::hexChannelToRgbChannel($this->green),
66
            Convert::hexChannelToRgbChannel($this->blue)
67
        );
68
69
        return new Hsla($hue, $saturation, $lightness, $alpha);
70
    }
71
72
    public function toRgb(): Rgb
73
    {
74
        return new Rgb(
75
            Convert::hexChannelToRgbChannel($this->red),
76
            Convert::hexChannelToRgbChannel($this->green),
77
            Convert::hexChannelToRgbChannel($this->blue)
78
        );
79
    }
80
81
    public function toRgba(float $alpha = 1): Rgba
82
    {
83
        return $this->toRgb()->toRgba($alpha);
84
    }
85
86
    public function __toString(): string
87
    {
88
        return "#{$this->red}{$this->green}{$this->blue}";
89
    }
90
}
91