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.

Rgb   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 90
c 0
b 0
f 0
wmc 11
lcom 1
cbo 6
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A red() 0 4 1
A green() 0 4 1
A blue() 0 4 1
A toHex() 0 8 1
A __construct() 0 10 1
A fromString() 0 12 1
A toHsl() 0 10 1
A toHsla() 0 10 1
A toRgb() 0 4 1
A toRgba() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace Spatie\Color;
4
5
class Rgb implements Color
6
{
7
    /** @var int */
8
    protected $red, $green, $blue;
9
10
    public function __construct(int $red, int $green, int $blue)
11
    {
12
        Validate::rgbChannelValue($red, 'red');
13
        Validate::rgbChannelValue($green, 'green');
14
        Validate::rgbChannelValue($blue, 'blue');
15
16
        $this->red = $red;
17
        $this->green = $green;
18
        $this->blue = $blue;
19
    }
20
21
    public static function fromString(string $string)
22
    {
23
        Validate::rgbColorString($string);
24
25
        $matches = null;
26
        preg_match('/rgb\( *(\d{1,3} *, *\d{1,3} *, *\d{1,3}) *\)/i', $string, $matches);
27
28
        $channels = explode(',', $matches[1]);
29
        [$red, $green, $blue] = array_map('trim', $channels);
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...
30
31
        return new static($red, $green, $blue);
32
    }
33
34
    public function red(): int
35
    {
36
        return $this->red;
37
    }
38
39
    public function green(): int
40
    {
41
        return $this->green;
42
    }
43
44
    public function blue(): int
45
    {
46
        return $this->blue;
47
    }
48
49
    public function toHex(): Hex
50
    {
51
        return new Hex(
52
            Convert::rgbChannelToHexChannel($this->red),
53
            Convert::rgbChannelToHexChannel($this->green),
54
            Convert::rgbChannelToHexChannel($this->blue)
55
        );
56
    }
57
58
    public function toHsl(): Hsl
59
    {
60
        [$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...
61
            $this->red,
62
            $this->green,
63
            $this->blue
64
        );
65
66
        return new Hsl($hue, $saturation, $lightness);
67
    }
68
69
    public function toHsla(float $alpha = 1): Hsla
70
    {
71
        [$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...
72
            $this->red,
73
            $this->green,
74
            $this->blue
75
        );
76
77
        return new Hsla($hue, $saturation, $lightness, $alpha);
78
    }
79
80
    public function toRgb(): self
81
    {
82
        return new self($this->red, $this->green, $this->blue);
83
    }
84
85
    public function toRgba(float $alpha = 1): Rgba
86
    {
87
        return new Rgba($this->red, $this->green, $this->blue, $alpha);
88
    }
89
90
    public function __toString(): string
91
    {
92
        return "rgb({$this->red},{$this->green},{$this->blue})";
93
    }
94
}
95