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.

RGBToHSLConverter::convert()   D
last analyzed

Complexity

Conditions 11
Paths 320

Size

Total Lines 35
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 11

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 23
c 1
b 0
f 0
nc 320
nop 1
dl 0
loc 35
ccs 24
cts 24
cp 1
crap 11
rs 4.9833

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 RGBToHSLConverter implements ConverterInterface
13
{
14 65
    public function convert(Color $color): Color
15
    {
16
        /* @var RGB $color */
17 65
        Assert::isInstanceOf($color, RGB::class, sprintf('color should be an instance of [%s]', RGB::class));
18
19 65
        $red = $color->getRed() / 255;
20 65
        $green = $color->getGreen() / 255;
21 65
        $blue = $color->getBlue() / 255;
22
23 65
        $cMax = max($red, $green, $blue);
24 65
        $cMin = min($red, $green, $blue);
25 65
        $cDelta = $cMax - $cMin;
26
27 65
        $hue = $cMax;
28
29 65
        if (0 == $cDelta) {
30 5
            $hue = 0;
31 60
        } elseif ($cMax === $red) {
32 26
            $hue = ($green - $blue) / $cDelta;
33 34
        } elseif ($cMax === $green) {
34 20
            $hue = ($blue - $red) / $cDelta + 2;
35 14
        } elseif ($cMax === $blue) {
36 14
            $hue = ($red - $green) / $cDelta + 4;
37
        }
38
39 65
        $hue = (int) round($hue * 60);
40 65
        $hue = $hue < 0 ? $hue + 360 : $hue;
41
42 65
        $lightning = ($cMax + $cMin) / 2;
43 65
        $saturation = 0 === $cDelta ? 0 : $cDelta / (1 - abs(2 * $lightning - 1));
44
45 65
        $saturation = $saturation > 1 || $saturation < 0 ? 1 : $saturation;
46 65
        $lightning = $lightning > 1 || $lightning < 0 ? 1 : $lightning;
47
48 65
        return new HSL($hue, $saturation * 100, $lightning * 100);
49
    }
50
51 924
    public static function supportsFrom(): string
52
    {
53 924
        return RGB::class;
54
    }
55
56 924
    public static function supportsTo(): string
57
    {
58 924
        return HSL::class;
59
    }
60
}
61