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.

HSVToRGBConverter::supportsFrom()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\HSV;
9
use Artack\Color\Color\RGB;
10
use Webmozart\Assert\Assert;
11
12
class HSVToRGBConverter implements ConverterInterface
13
{
14 132
    public function convert(Color $color): Color
15
    {
16
        /* @var HSV $color */
17 132
        Assert::isInstanceOf($color, HSV::class, sprintf('color should be an instance of [%s]', HSV::class));
18
19 131
        $h = $color->getHue();
20 131
        $s = $color->getSaturation() / 100;
21 131
        $v = $color->getValue() / 100;
22
23 131
        $hF = floor($h / 60);
24 131
        $f = $h / 60 - $hF;
25
26 131
        $p = $v * (1 - $s);
27 131
        $q = $v * (1 - $s * $f);
28 131
        $t = $v * (1 - $s * (1 - $f));
29
30 131
        switch ($hF) {
31 131
            case 0:
32 31
                $r = $v;
33 31
                $g = $t;
34 31
                $b = $p;
35 31
                break;
36 100
            case 1:
37 20
                $r = $q;
38 20
                $g = $v;
39 20
                $b = $p;
40 20
                break;
41 80
            case 2:
42 20
                $r = $p;
43 20
                $g = $v;
44 20
                $b = $t;
45 20
                break;
46 60
            case 3:
47 20
                $r = $p;
48 20
                $g = $q;
49 20
                $b = $v;
50 20
                break;
51 40
            case 4:
52 20
                $r = $t;
53 20
                $g = $p;
54 20
                $b = $v;
55 20
                break;
56 20
            case 5:
57 20
                $r = $v;
58 20
                $g = $p;
59 20
                $b = $q;
60 20
                break;
61
        }
62
63 131
        return new RGB((int) round($r * 255), (int) round($g * 255), (int) round($b * 255));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $b does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $g does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $r does not seem to be defined for all execution paths leading up to this point.
Loading history...
64
    }
65
66 924
    public static function supportsFrom(): string
67
    {
68 924
        return HSV::class;
69
    }
70
71 924
    public static function supportsTo(): string
72
    {
73 924
        return RGB::class;
74
    }
75
}
76