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 ( 73245c...f6f85c )
by w3l
01:33
created

Strings::rainbowText()   D

Complexity

Conditions 9
Paths 6

Size

Total Lines 42
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

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