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 ( 8dbce3...a69053 )
by Patrick
02:15
created

Transition::interpolate()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 5
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Artack\Color;
6
7
use Artack\Color\Color\Color;
8
use Artack\Color\Transition\TransitionInterface;
9
use Webmozart\Assert\Assert;
10
11
class Transition
12
{
13
    /** @var TransitionInterface[] */
14
    private $transitions = [];
15
16
    /** @var Converter */
17
    private $converter;
18
19
    /**
20
     * @param TransitionInterface[] $transitions
21
     * @param Converter             $converter
22
     */
23
    public function __construct(array $transitions, Converter $converter)
24
    {
25
        foreach ($transitions as $transition) {
26
            $this->addTransition($transition);
27
        }
28
29
        $this->converter = $converter;
30
    }
31
32
    private function addTransition(TransitionInterface $transition)
33
    {
34
        $this->transitions[] = $transition;
35
    }
36
37
    public function interpolate(string $fqcn, Color $startColor, Color $endColor, float $value, float $max): Color
38
    {
39
        Assert::greaterThanEq($max, 0, 'max needs to be 0 or greater');
40
        Assert::range($value, 0, $max, 'value needs to be in the range of 0 to max');
41
        Assert::lessThanEq($value, $max, 'value needs to be less or equal than max');
42
43
        if (get_class($startColor) !== $fqcn) {
44
            $startColor = $this->converter->convert($startColor, $fqcn);
45
        }
46
47
        if (get_class($endColor) !== $fqcn) {
48
            $endColor = $this->converter->convert($endColor, $fqcn);
49
        }
50
51
        return $this->getTransition($fqcn)->interpolate($startColor, $endColor, $value, $max);
52
    }
53
54
    private function getTransition(string $fqcn): TransitionInterface
55
    {
56
        foreach ($this->transitions as $transition) {
57
            if ($transition->supports($fqcn)) {
58
                return $transition;
59
            }
60
        }
61
62
        throw new \RuntimeException('no transition found getTransition');
63
    }
64
}
65