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

Convert   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 77
Duplicated Lines 23.38 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 20
lcom 0
cbo 0
dl 18
loc 77
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hexChannelToRgbChannel() 0 4 1
A rgbChannelToHexChannel() 0 4 1
C hslValueToRgb() 18 32 13
A rgbValueToHsl() 0 31 5

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 Convert
6
{
7
    public static function hexChannelToRgbChannel(string $hexValue): int
8
    {
9
        return hexdec($hexValue);
10
    }
11
12
    public static function rgbChannelToHexChannel(int $rgbValue): string
13
    {
14
        return str_pad(dechex($rgbValue), 2, '0', STR_PAD_LEFT);
15
    }
16
17
    public static function hslValueToRgb(float $hue, float $saturation, float $lightness): array
18
    {
19
        $c = (1 - abs(2 * ($lightness / 100) - 1)) * ($saturation / 100);
20
        $x = $c * (1 - abs(fmod($hue / 60, 2) - 1));
21
        $m = ($lightness / 100) - ($c / 2);
22
23
        $h = (360 + ($hue % 360)) % 360;  // hue values can be less than 0 and greater than 360. This normalises them into the range 0-360.
24
25 View Code Duplication
        if ($h > 0 && $h <= 60) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
26
            return [round(($c + $m) * 255), round(($x + $m) * 255), round($m * 255)];
27
        }
28
29 View Code Duplication
        if ($h > 60 && $h <= 120) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
30
            return [round(($x + $m) * 255), round(($c + $m) * 255), round($m * 255)];
31
        }
32
33 View Code Duplication
        if ($h > 120 && $h <= 180) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
34
            return [round($m * 255), round(($c + $m) * 255), round(($x + $m) * 255)];
35
        }
36
37 View Code Duplication
        if ($h > 180 && $h <= 240) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
38
            return [round($m * 255), round(($x + $m) * 255), round(($c + $m) * 255)];
39
        }
40
41 View Code Duplication
        if ($h > 240 && $h <= 300) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
42
            return [round(($x + $m) * 255), round($m * 255), round(($c + $m) * 255)];
43
        }
44
45 View Code Duplication
        if ($h > 300 && $h <= 360) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
46
            return [round(($c + $m) * 255), round($m * 255), round(($x + $m) * 255)];
47
        }
48
    }
49
50
    public static function rgbValueToHsl($red, $green, $blue)
51
    {
52
        $r = $red / 255;
53
        $g = $green / 255;
54
        $b = $blue / 255;
55
56
        $cmax = max($r, $g, $b);
57
        $cmin = min($r, $g, $b);
58
        $delta = $cmax - $cmin;
59
60
        $hue = 0;
61
        if ($delta !== 0) {
62
            if ($r === $cmax) {
63
                $hue = 60 * fmod(($g - $b) / $delta, 6);
64
            }
65
66
            if ($g === $cmax) {
67
                $hue = 60 * ((($b - $r) / $delta) + 2);
68
            }
69
70
            if ($b === $cmax) {
71
                $hue = 60 * ((($r - $g) / $delta) + 4);
72
            }
73
        }
74
75
        $lightness = ($cmax + $cmin) / 2;
76
77
        $saturation = $delta / (1 - abs((2 * $lightness) - 1));
78
79
        return [$hue, min($saturation, 1) * 100, min($lightness, 1) * 100];
80
    }
81
}
82