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

Hsl   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 93
Duplicated Lines 18.28 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 17
loc 93
c 0
b 0
f 0
wmc 14
lcom 1
cbo 6
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A fromString() 9 9 1
A hue() 0 4 1
A saturation() 0 4 1
A lightness() 0 4 1
A red() 0 4 1
A green() 0 4 1
A blue() 0 4 1
A toHex() 8 8 1
A toHsl() 0 4 1
A toHsla() 0 4 1
A toRgb() 0 4 1
A toRgba() 0 4 1
A __toString() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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