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 — dev ( 3d92be...f468a1 )
by w3l
02:00
created

Strings   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 236
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 10
Bugs 1 Features 0
Metric Value
wmc 26
c 10
b 1
f 0
lcom 0
cbo 0
dl 0
loc 236
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A obfuscateString() 0 4 1
A deobfuscateString() 0 4 1
A textareaEncode() 0 4 1
A textareaDecode() 0 4 1
A replaceString() 0 7 2
C rainbowText() 0 49 9
C kbdSymbol() 0 68 8
A kbdShortcut() 0 20 3
1
<?php
2
/**
3
 * Strings.php
4
 */
5
namespace w3l\Holt45;
6
7
/**
8
 * Handle strings(convert, encode, replace, etc).
9
 */
10
trait Strings
11
{
12
    /**
13
     * Obfuscate string (url-safe and somewhat hard to guess).
14
     *
15
     * @param string $input The text that should be obfuscated
16
     * @return string Obfuscated string
17
     */
18
    public static function obfuscateString($input)
19
    {
20
        return bin2hex(base64_encode(strrev($input)));
21
    }
22
23
    /**
24
     * Deobfuscate string
25
     *
26
     * @param string $input Obfuscated string
27
     * @return string Deobfuscated string
28
     */
29
    public static function deobfuscateString($input)
30
    {
31
        return strrev(base64_decode(hex2bin($input)));
32
    }
33
34
    /**
35
     * Convert <textarea> to [textarea].
36
     *
37
     * @param string $html
38
     * @return string
39
     */
40
    public static function textareaEncode($html)
41
    {
42
        return preg_replace("/<textarea(.*?)>(.*?)<\/textarea>/is", "[textarea$1]$2[/textarea]", $html);
43
    }
44
45
    /**
46
     * Convert [textarea] to <textarea>.
47
     *
48
     * @param string $html
49
     * @return string
50
     */
51
    public static function textareaDecode($html)
52
    {
53
        return preg_replace("/\[textarea(.*?)\](.*?)\[\/textarea\]/is", "<textarea$1>$2</textarea>", $html);
54
    }
55
56
    /**
57
     * To replace "Hallo [@var] world" with $value.
58
     *
59
     * Example:
60
     * ```php
61
     * replace_string($string, array("val1" => "foo", "val2" => "bar"))
62
     * ```
63
     *
64
     * @param string $langString String containing placeholder.
65
     * @param array $dynamicContent key->value array.
66
     * @return string String with placeholder replaced.
67
     */
68
    public static function replaceString($langString, $dynamicContent = array())
69
    {
70
        foreach ($dynamicContent as $k => $v) {
71
            $langString = str_replace("[@".$k."]", $v, $langString);
72
        }
73
        return $langString;
74
    }
75
76
    /**
77
     * Creates rainbow-colored text.
78
     *
79
     * @uses Holt45::colorBlend()
80
     * @uses Holt45::rgbhex()
81
     *
82
     * @param string $text Text wanted coloured.
83
     * @return string String with span-tags with color.
84
     */
85
    public static function rainbowText($text)
86
    {
87
        $colorsBase = array(
88
        array(255, 0, 0),
89
        array(255, 102, 0),
90
        array(255, 238, 0),
91
        array(0, 255, 0),
92
        array(0, 153, 255),
93
        array(68, 0, 255),
94
        array(153, 0, 255)
95
        );
96
97
        $colorsBuild = array();
98
99
        $strlenText = strlen($text);
100
101
        if ($strlenText > 7) {
102
            while (count($colorsBuild) < $strlenText) {
103
                for ($i = 0, $size = count($colorsBase); $i < $size; $i++) {
104
105
                    $colorsBuild[] = $colorsBase[$i];
106
107
                    if (count($colorsBuild) >= $strlenText) {
108
                        continue 2;
109
                    }
110
111
                    if ($i < count($colorsBase)-1) {
112
113
                        $colorsBuild[] = self::colorBlend($colorsBase[$i], $colorsBase[$i+1]);
114
115
                        if (count($colorsBuild) >= $strlenText) {
116
                            continue 2;
117
                        }
118
                    }
119
                }
120
                $colorsBase = $colorsBuild;
121
                $colorsBuild = array();
122
            }
123
        } elseif ($strlenText <= 7) {
124
            $colorsBuild = $colorsBase;
125
        }
126
127
        $arrayText = str_split($text);
128
        $returnText = "";
129
        for ($i = 0, $size = count($arrayText); $i < $size; $i++) {
130
            $returnText .= '<span style="color: #'.self::rgbhex($colorsBuild[$i]).';">'.$arrayText[$i].'</span>';
131
        }
132
        return $returnText;
133
    }
134
    
135
    /**
136
     * Get the symbol from a list of keyboard-keys...
137
     *
138
     * @used-by Holt45::kbdShortcut()
139
     *
140
     * @param string $inputKey Text
141
     * @param string $inputOperatingSystem default|auto|win|mac|linux
142
     * @return null|string HTML Entity (decimal)
143
     */
144
    public static function kbdSymbol($inputKey, $inputOperatingSystem = "default")
145
    {   
146
        $inputKey = mb_strtolower($inputKey);
147
        
148
        if($inputOperatingSystem == "auto") {
149
            
150
            $inputOperatingSystem = "default";
151
            
152
            $getClientOperatingSystem = self::getClientOperatingSystem();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $getClientOperatingSystem exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
153
            
154
            if ($getClientOperatingSystem == "linux" || 
155
                $getClientOperatingSystem == "mac" ||
156
                $getClientOperatingSystem == "win") {
157
                   $inputOperatingSystem = $getClientOperatingSystem;
158
            }
159
        }
160
        
161
        $arrayConvert = array(
162
        "return" => "enter",
163
        "control" => "ctrl",
164
        "escape" => "esc",
165
        "caps lock" => "caps-lock",
166
        "page up" => "page-up",
167
        "page down" => "page-down",
168
        "arrow left" => "arrow-left",
169
        "left" => "arrow-left",
170
        "arrow up" => "arrow-up",
171
        "up" => "arrow-up",
172
        "arrow right" => "arrow-right",
173
        "right" => "arrow-right",
174
        "arrow down" => "arrow-down",
175
        "down" => "arrow-down"
176
        );
177
        
178
        /* Convert input */
179
        if (array_key_exists($inputKey, $arrayConvert)) {
180
            $inputKey = $arrayConvert[$inputKey];
181
        }
182
183
        $arrayKeySymbols = array(
184
        "shift" => array("default" => "&#8679;"),
185
        "opt" => array("default" => "&#8997;"),
186
        "enter" => array("default" => "&#9166;", "mac" => "&#8996;"),
187
        "alt" => array("default" => "&#9095;", "mac" => "&#8997;"),
188
        "delete" => array("default" => "&#9003;"),
189
        "ctrl" => array("default" => "&#10034;", "win" => "&#10034;", "linux" => "&#9096;", "mac" => "&#00094;"),
190
        "esc" => array("default" => "&#9099;"),
191
        "command" => array("default" => "&#8984;"),
192
        "tab" => array("default" => "&#8633;", "mac" => "&#8677;"),
193
        "caps-lock" => array("default" => "&#65;", "mac" => "&#8682;"),
194
        "page-up" => array("default" => "&#9650;", "mac" => "&#8670;"),
195
        "page-down" => array("default" => "&#9660;", "mac" => "&#8671;"),
196
        "arrow-left" => array("default" => "&#8592;"),
197
        "arrow-up" => array("default" => "&#8593;"),
198
        "arrow-right" => array("default" => "&#8594;"),
199
        "arrow-down" => array("default" => "&#8595;"),
200
        // Sun
201
        "compose" => array("default" => "&#9092;"),
202
        "meta" => array("default" => "&#9670")
203
        );
204
        
205
        if (array_key_exists($inputKey, $arrayKeySymbols)) {
206
            
207
            return ((array_key_exists($inputOperatingSystem, $arrayKeySymbols[$inputKey])) ? $arrayKeySymbols[$inputKey][$inputOperatingSystem] : $arrayKeySymbols[$inputKey]["default"]);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 186 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
208
        }
209
        
210
        return null;
211
    }
212
213
    /**
214
     * Show fancy buttons for keyboard-shortcuts.
215
     *
216
     * @uses Holt45::kbdSymbol()
217
     *
218
     * @param array $inputArrayKeys
219
     * @param string $inputOperatingSystem
220
     * @param string $inputKbdClass
221
     * @param string $inputKbdSymbolClass
222
     * @param string $inputJoinHtml Glue
0 ignored issues
show
Bug introduced by
There is no parameter named $inputJoinHtml. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
223
     * @return string String of html
224
     */
225
    public static function kbdShortcut($inputArrayKeys, $inputOperatingSystem = "default", $inputKbdClass = "holt45-kbd", $inputKbdSymbolClass = "holt45-kbd__symbol", $inputJoinGlue = " + ")
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 190 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
226
    {
227
        $returnArray = array();
228
229
        foreach ($inputArrayKeys AS $key) {
230
            
231
            $kbdSymbol = self::kbdSymbol($key, $inputOperatingSystem);
232
            
233
            $kbdSymbolHtml = "";
234
            
235
            if ($kbdSymbol !== NULL) {
236
                $kbdSymbolHtml = '<span class="'.$inputKbdSymbolClass.'">'.$kbdSymbol.'</span>';
237
            }
238
            
239
            $returnArray[] = '<kbd class="'.$inputKbdClass.'">'.$kbdSymbolHtml.$key.'</kbd>';
240
            
241
        }
242
243
        return implode($inputJoinGlue, $returnArray);
244
    }
245
}
246