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 ( 057a6c...74479f )
by w3l
07:23 queued 05:26
created

Strings::cssOneLineText()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 3
eloc 11
nc 4
nop 4
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 == "windows") {
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;", "windows" => "&#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])) ?
208
                                      $arrayKeySymbols[$inputKey][$inputOperatingSystem] :
209
                                      $arrayKeySymbols[$inputKey]["default"]);
210
        }
211
        
212
        return null;
213
    }
214
215
    /**
216
     * Show fancy buttons for keyboard-shortcuts.
217
     *
218
     * @uses Holt45::kbdSymbol()
219
     *
220
     * @param array $inputArrayKeys
221
     * @param string $inputOperatingSystem
222
     * @param string $inputKbdClass
223
     * @param string $inputKbdSymbolClass
224
     * @param string $inputJoinGlue Glue
225
     * @return string String of html
226
     */
227
    public static function kbdShortcut(
228
        $inputArrayKeys,
229
        $inputOperatingSystem = "default",
230
        $inputKbdClass = "holt45-kbd",
231
        $inputKbdSymbolClass = "holt45-kbd__symbol",
232
        $inputJoinGlue = " + "
233
    ) {
234
        $returnArray = array();
235
236
        foreach ($inputArrayKeys as $key) {
237
            
238
            $kbdSymbol = self::kbdSymbol($key, $inputOperatingSystem);
239
            
240
            $kbdSymbolHtml = "";
241
            
242
            if ($kbdSymbol !== null) {
243
                $kbdSymbolHtml = '<span class="'.$inputKbdSymbolClass.'">'.$kbdSymbol.'</span>';
244
            }
245
            
246
            $returnArray[] = '<kbd class="'.$inputKbdClass.'">'.$kbdSymbolHtml.$key.'</kbd>';
247
            
248
        }
249
250
        return implode($inputJoinGlue, $returnArray);
251
    }
252
253
    /**
254
     * Attempting to keep CSS on one line with scoped style.
255
     *
256
     * NOTICE: This is a rough estimate, font type, design, etc affects the results.
257
     *
258
     * @param string $text
259
     * @param string $cssSelector
260
     * @param int $fontSizePx
261
     * @param int $minPageWidthPx
262
     * @return null|string Scoped style
263
     */
264
    public static function cssOneLineText($text, $cssSelector = "h1", $fontSizePx = 36, $minPageWidthPx = 320)
265
    {
266
        $countText = strlen($text)+1;
267
268
        $fontWidth = ($fontSizePx / 2);
269
270
        if ($minPageWidthPx < $countText) {
271
            $minPageWidthPx = $countText;
272
        }
273
        if (($countText * $fontWidth) > $minPageWidthPx) {
274
275
            $cssNewFontSizePx = round(($minPageWidthPx / $countText) * 2, 2);
276
            $cssNewFontSizeVw = round((100/$countText) * 2, 2);
277
278
            $cssBreakpointPx = round($countText * $fontWidth);
279
280
            return '<style scoped>@media (max-width: '.$cssBreakpointPx.'px) { '.$cssSelector.' { font-size: '.$cssNewFontSizePx.'px; font-size: '.$cssNewFontSizeVw.'vw; } }</style>';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 183 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...
281
        }
282
        return null;
283
    }
284
}
285