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.

HSLToRGBConverter::convert()   B
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 47
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 40
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 39
c 1
b 0
f 0
nc 7
nop 1
dl 0
loc 47
ccs 40
cts 40
cp 1
crap 7
rs 8.3626
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Artack\Color\Converter;
6
7
use Artack\Color\Color\Color;
8
use Artack\Color\Color\HSL;
9
use Artack\Color\Color\RGB;
10
use Webmozart\Assert\Assert;
11
12
class HSLToRGBConverter implements ConverterInterface
13
{
14 65
    public function convert(Color $color): Color
15
    {
16
        /* @var HSL $color */
17 65
        Assert::isInstanceOf($color, HSL::class, sprintf('color should be an instance of [%s]', HSL::class));
18
19 65
        $hue = $color->getHue();
20 65
        $saturation = $color->getSaturation() / 100;
21 65
        $lightness = $color->getLightness() / 100;
22
23 65
        $c = (1 - abs(2 * $lightness - 1)) * $saturation; // 0.5
24 65
        $x = $c * (1 - abs(fmod($hue / 60, 2) - 1));
25 65
        $m = $lightness - $c / 2; // 0.25
26
27 65
        switch (floor($hue / 60)) {
28 65
            case 0:
29 15
                $red = $c;
30 15
                $green = $x;
31 15
                $blue = 0;
32 15
                break;
33 50
            case 1:
34 10
                $red = $x;
35 10
                $green = $c;
36 10
                $blue = 0;
37 10
                break;
38 40
            case 2:
39 10
                $red = 0;
40 10
                $green = $c;
41 10
                $blue = $x;
42 10
                break;
43 30
            case 3:
44 10
                $red = 0;
45 10
                $green = $x;
46 10
                $blue = $c;
47 10
                break;
48 20
            case 4:
49 10
                $red = $x;  //  >> 64 ???
50 10
                $green = 0; // >> 64
51 10
                $blue = $c; // 0.5 >> (0.25+0.5)*255 >> 191.25 >> 191 OK
52 10
                break;
53 10
            case 5:
54 10
                $red = $c;
55 10
                $green = 0;
56 10
                $blue = $x;
57 10
                break;
58
        }
59
60 65
        return new RGB((int) round(($red + $m) * 255), (int) round(($green + $m) * 255), (int) round(($blue + $m) * 255));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $blue does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $red does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $green does not seem to be defined for all execution paths leading up to this point.
Loading history...
61
    }
62
63 924
    public static function supportsFrom(): string
64
    {
65 924
        return HSL::class;
66
    }
67
68 924
    public static function supportsTo(): string
69
    {
70 924
        return RGB::class;
71
    }
72
}
73