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.

Convert::hexrgb()   B
last analyzed

Complexity

Conditions 6
Paths 9

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 13
nc 9
nop 1
dl 0
loc 22
rs 8.6737
c 0
b 0
f 0
1
<?php
2
/**
3
 * Convert.php
4
 */
5
namespace w3l\Holt45;
6
7
/**
8
 * Convert and manipulate values.
9
 */
10
trait Convert
11
{
12
    /**
13
     * Converts red-green-blue(RGB) to hexadecimal
14
     *
15
     * @param array $rgb RGB color
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $rgb a bit more specific; maybe use array[].
Loading history...
16
     * @return string Hexadecimal color
17
     */
18
    public static function rgbhex(...$rgb)
19
    {
20
        // If first value is array, then create array from first value
21
        if ((array)$rgb[0] === $rgb[0]) {
22
            $rgb = $rgb[0];
23
        }
24
        
25
        $hex = "";
26
        foreach ($rgb as $color) {
27
            $hex .= str_pad(dechex($color), 2, "0", STR_PAD_LEFT);
28
        }
29
        return $hex;
30
    }
31
32
    /**
33
     * Converts hexadecimal to red-green-blue(RGB)
34
     *
35
     * @used-by Holt45::rainbowText();
36
     *
37
     * @param string $hex Hexadecimal color
38
     * @return null|int[] RGB color
0 ignored issues
show
Documentation introduced by
Should the return type not be array<integer|double>|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
39
     */
40
    public static function hexrgb($hex)
41
    {
42
        $hex = preg_replace("/[^0-9A-Fa-f]/", '', $hex);
43
44
        $strlenHex = strlen($hex);
45
46
        if ($strlenHex >= 3) {
47
            if ($strlenHex >= 6) {
48
                if ($strlenHex > 6) {
49
                    $hex = substr($hex, 0, 6);
50
                }
51
                $hexArray = str_split($hex, 2);
52
            } elseif ($strlenHex < 6) {
53
                $hexArray = array("$hex[0]$hex[0]", "$hex[1]$hex[1]", "$hex[2]$hex[2]");
54
            }
55
            if (isset($hexArray)) {
56
                return array(hexdec($hexArray[0]), hexdec($hexArray[1]), hexdec($hexArray[2]));
57
            }
58
        }
59
60
        return null;
61
    }
62
63
    /**
64
     * Converts hexadecimal to red-green-blue(RGB)
65
     *
66
     * @used-by Holt45::rainbowText();
67
     *
68
     * @param array $arrayRGB RGB color
69
     * @param array $arrayRGB2 RGB color
70
     * @return int[] Blended RGB color
71
     */
72
    public static function colorBlend($arrayRGB, $arrayRGB2)
73
    {
74
        $arrayBlend = array();
75
76
        for ($i = 0, $size = count($arrayRGB); $i < $size; $i++) {
77
            $arrayBlend[] = round(($arrayRGB[$i]+$arrayRGB2[$i])/2);
78
        }
79
80
        return $arrayBlend;
81
    }
82
}
83