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.

RGBToCMYKConverter::convert()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 19
ccs 12
cts 12
cp 1
crap 4
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Artack\Color\Converter;
6
7
use Artack\Color\Color\CMYK;
8
use Artack\Color\Color\Color;
9
use Artack\Color\Color\RGB;
10
use Webmozart\Assert\Assert;
11
12
class RGBToCMYKConverter 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 * 100;
20 65
        $green = $color->getGreen() / 255 * 100;
21 65
        $blue = $color->getBlue() / 255 * 100;
22
23 65
        if (0 === $red && 0 === $green && 0 === $blue) {
24 1
            return new CMYK(0, 0, 0, 100);
25
        }
26
27 64
        $key = 100 - max($red, $green, $blue);
28 64
        $cyan = ((100 - $red - $key) / (100 - $key)) * 100;
29 64
        $magenta = ((100 - $green - $key) / (100 - $key)) * 100;
30 64
        $yellow = ((100 - $blue - $key) / (100 - $key)) * 100;
31
32 64
        return new CMYK($cyan, $magenta, $yellow, $key);
33
    }
34
35 924
    public static function supportsFrom(): string
36
    {
37 924
        return RGB::class;
38
    }
39
40 924
    public static function supportsTo(): string
41
    {
42 924
        return CMYK::class;
43
    }
44
}
45