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 ( 043ac2...816202 )
by w3l
06:45 queued 05:13
created

Strings::rainbowText()   C

Complexity

Conditions 9
Paths 6

Size

Total Lines 49
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 49
rs 5.7446
cc 9
eloc 30
nc 6
nop 1
1
<?php
2
namespace w3l\Holt45;
3
4
trait Strings
5
{
6
    /**
7
     * Obfuscate string (url-safe and somewhat hard to guess).
8
     *
9
     * @param string $input The text that should be obfuscated
10
     * @return string Obfuscated string
11
     */
12
    public static function obfuscateString($input)
13
    {
14
        return bin2hex(base64_encode(strrev($input)));
15
    }
16
17
    /**
18
     * Deobfuscate string
19
     *
20
     * @param string $input Obfuscated string
21
     * @return string Deobfuscated string
22
     */
23
    public static function deobfuscateString($input)
24
    {
25
        return strrev(base64_decode(hex2bin($input)));
26
    }
27
28
    /**
29
     * Convert <textarea> to [textarea].
30
     *
31
     * @param string $html
32
     * @return string
33
     */
34
    public static function textareaEncode($html)
35
    {
36
        return preg_replace("/<textarea(.*?)>(.*?)<\/textarea>/is", "[textarea$1]$2[/textarea]", $html);
37
    }
38
39
    /**
40
     * Convert [textarea] to <textarea>.
41
     *
42
     * @param string $html
43
     * @return string
44
     */
45
    public static function textareaDecode($html)
46
    {
47
        return preg_replace("/\[textarea(.*?)\](.*?)\[\/textarea\]/is", "<textarea$1>$2</textarea>", $html);
48
    }
49
50
    /**
51
     * To replace "Hallo [@var] world" with $value.
52
     *
53
     * @example replace_string($string, array("val1" => "foo", "val2" => "bar"))
54
     *
55
     * @param string $langString String containing placeholder.
56
     * @param array $dynamicContent key->value array.
57
     * @return string String with placeholder replaced.
58
     */
59
    public static function replaceString($langString, $dynamicContent = array())
60
    {
61
        foreach ($dynamicContent as $k => $v) {
62
            $langString = str_replace("[@".$k."]", $v, $langString);
63
        }
64
        return $langString;
65
    }
66
67
    /**
68
     * Creates rainbow-colored text.
69
     *
70
     * @param string $text Text wanted coloured.
71
     * @return string String with span-tags with color.
72
     */
73
    public static function rainbowText($text)
74
    {
75
        $colorsBase = array(
76
        array(255, 0, 0),
77
        array(255, 102, 0),
78
        array(255, 238, 0),
79
        array(0, 255, 0),
80
        array(0, 153, 255),
81
        array(68, 0, 255),
82
        array(153, 0, 255)
83
        );
84
85
        $colorsBuild = array();
86
87
        $strlenText = strlen($text);
88
89
        if ($strlenText > 7) {
90
            while (count($colorsBuild) < $strlenText) {
91
                for ($i = 0, $size = count($colorsBase); $i < $size; $i++) {
92
93
                    $colorsBuild[] = $colorsBase[$i];
94
95
                    if (count($colorsBuild) >= $strlenText) {
96
                        continue 2;
97
                    }
98
99
                    if ($i < count($colorsBase)-1) {
100
101
                        $colorsBuild[] = self::colorBlend($colorsBase[$i], $colorsBase[$i+1]);
102
103
                        if (count($colorsBuild) >= $strlenText) {
104
                            continue 2;
105
                        }
106
                    }
107
                }
108
                $colorsBase = $colorsBuild;
109
                $colorsBuild = array();
110
            }
111
        } elseif ($strlenText <= 7) {
112
            $colorsBuild = $colorsBase;
113
        }
114
115
        $arrayText = str_split($text);
116
        $returnText = "";
117
        for ($i = 0, $size = count($arrayText); $i < $size; $i++) {
118
            $returnText .= '<span style="color: #'.self::rgbhex($colorsBuild[$i]).';">'.$arrayText[$i].'</span>';
119
        }
120
        return $returnText;
121
    }
122
}
123