| Conditions | 1 |
| Paths | 1 |
| Total Lines | 15 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 1 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | 9 | public function interpolate(Color $startColor, Color $endColor, float $value, float $max): Color |
|
| 14 | { |
||
| 15 | /* @var RGB $startColor */ |
||
| 16 | 9 | Assert::isInstanceOf($startColor, RGB::class, sprintf('startColor needs to be an instance of [%s]', RGB::class)); |
|
| 17 | |||
| 18 | /* @var RGB $endColor */ |
||
| 19 | 8 | Assert::isInstanceOf($endColor, RGB::class, sprintf('endColor needs to be an instance of [%s]', RGB::class)); |
|
| 20 | |||
| 21 | 8 | $step = $value / $max; |
|
| 22 | |||
| 23 | 8 | $red = $startColor->getRed() + ($endColor->getRed() - $startColor->getRed()) * $step; |
|
| 24 | 8 | $green = $startColor->getGreen() + ($endColor->getGreen() - $startColor->getGreen()) * $step; |
|
| 25 | 8 | $blue = $startColor->getBlue() + ($endColor->getBlue() - $startColor->getBlue()) * $step; |
|
| 26 | |||
| 27 | 8 | return new RGB((int) round($red), (int) round($green), (int) round($blue)); |
|
| 28 | } |
||
| 35 |