Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ColorUtils
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
n/a
0 / 0
n/a
0 / 0
1
 intToRgb
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 rgbToInt
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   phpOMS\Utils
8 * @copyright Dennis Eichhorn
9 * @license   OMS License 2.0
10 * @version   1.0.0
11 * @link      https://jingga.app
12 */
13declare(strict_types=1);
14
15namespace phpOMS\Utils;
16
17/**
18 * Color class for color operations.
19 *
20 * @package phpOMS\Utils
21 * @license OMS License 2.0
22 * @link    https://jingga.app
23 * @since   1.0.0
24 */
25final class ColorUtils
26{
27    /**
28     * Constructor.
29     *
30     * @since 1.0.0
31     * @codeCoverageIgnore
32     */
33    private function __construct()
34    {
35    }
36
37    /**
38     * Convert int to rgb
39     *
40     * @param int $rgbInt Value to convert
41     *
42     * @return array{r:int, g:int, b:int}
43     *
44     * @since 1.0.0
45     */
46    public static function intToRgb(int $rgbInt) : array
47    {
48        $rgb = ['r' => 0, 'g' => 0, 'b' => 0];
49
50        $rgb['b'] = $rgbInt & 255;
51        $rgb['g'] = ($rgbInt >> 8) & 255;
52        $rgb['r'] = ($rgbInt >> 16) & 255;
53
54        return $rgb;
55    }
56
57    /**
58     * Convert rgb to int
59     *
60     * @param array{r:int, g:int, b:int} $rgb Int rgb array
61     *
62     * @return int
63     *
64     * @since 1.0.0
65     */
66    public static function rgbToInt(array $rgb) : int
67    {
68        $i  = (255 & $rgb['r']) << 16;
69        $i += (255 & $rgb['g']) << 8;
70        $i += (255 & $rgb['b']);
71
72        return $i;
73    }
74}