Completed
Push — master ( 8ced3e...c66cb3 )
by smiley
02:28
created
src/Base32.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
  * -----------
30 30
  * For dealing with humans it's probably best to use csSafe rather then csRFC3548
31 31
  */
32
-class Base32{
32
+class Base32 {
33 33
 
34 34
 	/**
35 35
 	 * charset
@@ -51,11 +51,11 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @throws \chillerlan\Base32\Base32Exception
53 53
 	 */
54
-	public static function setCharset($charset = Base32Characters::RFC3548){
55
-		if(strlen($charset) === 32){
54
+	public static function setCharset($charset = Base32Characters::RFC3548) {
55
+		if (strlen($charset) === 32) {
56 56
 			self::$charset = strtoupper($charset);
57 57
 		}
58
-		else{
58
+		else {
59 59
 			throw new Base32Exception('Length must be exactly 32');
60 60
 		}
61 61
 	}
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return string String of 0's and 1's
71 71
 	 */
72
-	public static function str2bin($str){
72
+	public static function str2bin($str) {
73 73
 		$chrs = unpack('C*', $str);
74 74
 
75 75
 		return vsprintf(str_repeat('%08b', count($chrs)), $chrs);
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * @return string The ascii output
86 86
 	 * @throws \chillerlan\Base32\Base32Exception
87 87
 	 */
88
-	public static function bin2str($str){
88
+	public static function bin2str($str) {
89 89
 		self::checkLength($str);
90 90
 		self::checkBin($str);
91 91
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 * @return string String encoded as base32
109 109
 	 * @throws \chillerlan\Base32\Base32Exception
110 110
 	 */
111
-	public static function fromBin($str){
111
+	public static function fromBin($str) {
112 112
 		self::checkLength($str);
113 113
 		self::checkBin($str);
114 114
 
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
 		$length = strlen($str);
120 120
 		$rbits = $length&7;
121 121
 
122
-		if($rbits > 0){
122
+		if ($rbits > 0) {
123 123
 			// Excessive bits need to be padded
124
-			$ebits = substr($str, $length-$rbits);
125
-			$str = substr($str, 0, $length-$rbits).'000'.$ebits.str_repeat('0', 5-strlen($ebits));
124
+			$ebits = substr($str, $length - $rbits);
125
+			$str = substr($str, 0, $length - $rbits).'000'.$ebits.str_repeat('0', 5 - strlen($ebits));
126 126
 		}
127 127
 
128 128
 		preg_match_all('/.{8}/', $str, $chrs);
129 129
 
130
-		$chrs = array_map(function ($str){
130
+		$chrs = array_map(function($str) {
131 131
 			return self::$charset[bindec($str)];
132 132
 		}, $chrs[0]);
133 133
 
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 	 * @return string Ascii binary string
145 145
 	 * @throws \chillerlan\Base32\Base32Exception
146 146
 	 */
147
-	public static function toBin($str){
147
+	public static function toBin($str) {
148 148
 		self::checkCharacterSet($str);
149 149
 
150 150
 		// Convert the base32 string back to a binary string
151
-		$str = array_map(function ($chr){
151
+		$str = array_map(function($chr) {
152 152
 			return sprintf('%08b', strpos(self::$charset, $chr));
153 153
 		}, str_split($str));
154 154
 
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
 		$length = strlen($str);
160 160
 		$rbits = $length&7;
161 161
 
162
-		if($rbits > 0){
163
-			$str = substr($str, 0, $length-$rbits);
162
+		if ($rbits > 0) {
163
+			$str = substr($str, 0, $length - $rbits);
164 164
 		}
165 165
 
166 166
 		return $str;
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	 *
177 177
 	 * @return string The converted base32 string
178 178
 	 */
179
-	public static function fromString($str){
179
+	public static function fromString($str) {
180 180
 		return self::fromBin(self::str2bin($str));
181 181
 	}
182 182
 
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
 	 *
191 191
 	 * @return string The normal string
192 192
 	 */
193
-	public static function toString($str){
193
+	public static function toString($str) {
194 194
 		$str = strtoupper($str);
195 195
 
196 196
 		// csSave actually has to be able to consider extra characters
197
-		if(self::$charset === Base32Characters::CROCKFORD){
197
+		if (self::$charset === Base32Characters::CROCKFORD) {
198 198
 			$str = str_replace('O', '0', $str);
199 199
 			$str = str_replace(['I', 'L'], '1', $str);
200 200
 		}
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 * @throws \chillerlan\Base32\Base32Exception
209 209
 	 */
210
-	protected static function checkLength($str){
211
-		if(strlen($str)%8 > 0){
210
+	protected static function checkLength($str) {
211
+		if (strlen($str) % 8 > 0) {
212 212
 			throw new Base32Exception('Length must be divisible by 8');
213 213
 		}
214 214
 	}
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
 	 *
219 219
 	 * @throws \chillerlan\Base32\Base32Exception
220 220
 	 */
221
-	protected static function checkBin($str){
222
-		if(!preg_match('/^[01]+$/', $str)){
221
+	protected static function checkBin($str) {
222
+		if (!preg_match('/^[01]+$/', $str)) {
223 223
 			throw new Base32Exception('Only 0 and 1 are permitted');
224 224
 		}
225 225
 	}
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @throws \chillerlan\Base32\Base32Exception
231 231
 	 */
232
-	protected static function checkCharacterSet($str){
233
-		if(!preg_match('/^['.self::$charset.']+$/', $str)){
232
+	protected static function checkCharacterSet($str) {
233
+		if (!preg_match('/^['.self::$charset.']+$/', $str)) {
234 234
 			throw new Base32Exception('Must match character set');
235 235
 		}
236 236
 	}
Please login to merge, or discard this patch.