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

Rgba::toRgba()   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 1
1
<?php
2
3
namespace Spatie\Color;
4
5
class Rgba implements Color
6
{
7
    /** @var int */
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
    /** @var float */
11
    protected $alpha;
12
13 View Code Duplication
    public function __construct(int $red, int $green, int $blue, float $alpha)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
    {
15
        Validate::rgbChannelValue($red, 'red');
16
        Validate::rgbChannelValue($green, 'green');
17
        Validate::rgbChannelValue($blue, 'blue');
18
        Validate::alphaChannelValue($alpha);
19
20
        $this->red = $red;
21
        $this->green = $green;
22
        $this->blue = $blue;
23
        $this->alpha = $alpha;
24
    }
25
26 View Code Duplication
    public static function fromString(string $string)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        Validate::rgbaColorString($string);
29
30
        $matches = null;
31
        preg_match('/rgba\( *(\d{1,3} *, *\d{1,3} *, *\d{1,3} *, *[0-1](\.\d{1,2})?) *\)/i', $string, $matches);
32
33
        $channels = explode(',', $matches[1]);
34
        list($red, $green, $blue, $alpha) = array_map('trim', $channels);
35
36
        return new static($red, $green, $blue, $alpha);
37
    }
38
39
    public function red(): int
40
    {
41
        return $this->red;
42
    }
43
44
    public function green(): int
45
    {
46
        return $this->green;
47
    }
48
49
    public function blue(): int
50
    {
51
        return $this->blue;
52
    }
53
54
    public function alpha(): float
55
    {
56
        return $this->alpha;
57
    }
58
59
    public function toHex(): Hex
60
    {
61
        return $this->toRgb()->toHex();
62
    }
63
64
    public function toRgb(): Rgb
65
    {
66
        return new Rgb($this->red, $this->green, $this->blue);
67
    }
68
69
    public function toRgba(float $alpha = 1): Rgba
70
    {
71
        return new self($this->red, $this->green, $this->blue, $alpha);
72
    }
73
74
    public function __toString(): string
75
    {
76
        $alpha = number_format($this->alpha, 2);
77
78
        return "rgba({$this->red},{$this->green},{$this->blue},{$alpha})";
79
    }
80
}
81