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 ( 2aea1d...51a001 )
by w3l
03:08
created

Strings   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 15
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 109
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A obfuscateString() 0 3 1
A deobfuscateString() 0 3 1
A textareaEncode() 0 3 1
A textareaDecode() 0 3 1
A replaceString() 0 7 2
D rainbowText() 0 42 9
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
	function rainbowText($text) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
69
		$colors_base = 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
		$colors_build = array();
80
81
		$strlenText = strlen($text);
82
83
		if($strlenText > 7) {
84
			while(count($colors_build) < $strlenText) {
85
				for($i = 0; $i < count($colors_base); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
86
87
					$colors_build[] = $colors_base[$i];
88
					if(count($colors_build) >= $strlenText) { continue 2; }
89
					
90
					if($i < count($colors_base)-1) {
91
						$colors_build[] = holt45::colorBlend($colors_base[$i], $colors_base[$i+1]);
92
						if(count($colors_build) >= $strlenText) { continue 2; }
93
					}
94
				}
95
				$colors_base = $colors_build;
96
				$colors_build = array();
97
			}
98
		} elseif($strlenText <= 7) {
99
			$colors_build = $colors_base;
100
		}
101
102
		$arrayText = str_split($text);
103
		$returnText = "";
104
		for($i = 0; $i < count($arrayText); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
105
			$returnText .= '<span style="color: #'.holt45::rgbhex($colors_build[$i]).';">'.$arrayText[$i].'</span>';
106
		}
107
		return $returnText;
108
109
	}
110
111
}
112