Completed
Push — feature/code-analysis ( ddc57d...5519b1 )
by Jonathan
09:07 queued 04:56
created
src/Webtrees/Functions/Functions.php 1 patch
Braces   +21 added lines, -13 removed lines patch added patch discarded remove patch
@@ -114,16 +114,18 @@  discard block
 block discarded – undo
114 114
 		$len_chars = count($chars);
115 115
 		$token = '';
116 116
 		
117
-		for ($i = 0; $i < $length; $i++)
118
-			$token .= $chars[ mt_rand(0, $len_chars - 1) ];
117
+		for ($i = 0; $i < $length; $i++) {
118
+					$token .= $chars[ mt_rand(0, $len_chars - 1) ];
119
+		}
119 120
 		
120 121
 		# Number of 32 char chunks
121 122
 		$chunks = ceil( strlen($token) / 32 );
122 123
 		$md5token = '';
123 124
 		
124 125
 		# Run each chunk through md5
125
-		for ( $i=1; $i<=$chunks; $i++ )
126
-			$md5token .= md5( substr($token, $i * 32 - 32, 32) );
126
+		for ( $i=1; $i<=$chunks; $i++ ) {
127
+					$md5token .= md5( substr($token, $i * 32 - 32, 32) );
128
+		}
127 129
 		
128 130
 			# Trim the token
129 131
 		return substr($md5token, 0, $length);		
@@ -138,8 +140,9 @@  discard block
 block discarded – undo
138 140
 	 */
139 141
 	public static function encryptToSafeBase64($data){
140 142
 		$key = 'STANDARDKEYIFNOSERVER';
141
-		if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE'))
142
-			$key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE'));
143
+		if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) {
144
+					$key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE'));
145
+		}
143 146
 		$iv = mcrypt_create_iv(self::ENCRYPTION_IV_SIZE, MCRYPT_RAND);
144 147
 		$id = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC,$iv);
145 148
 		$encrypted = base64_encode($iv.$id);
@@ -158,16 +161,19 @@  discard block
 block discarded – undo
158 161
 	 */
159 162
 	public static function decryptFromSafeBase64($encrypted){
160 163
 		$key = 'STANDARDKEYIFNOSERVER';
161
-		if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE'))
162
-			$key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE'));
164
+		if(Filter::server('SERVER_NAME') && Filter::server('SERVER_SOFTWARE')) {
165
+					$key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE'));
166
+		}
163 167
 		$encrypted = str_replace('-', '+', $encrypted);
164 168
 		$encrypted = str_replace('_', '/', $encrypted);
165 169
 		$encrypted = str_replace('*', '=', $encrypted);
166 170
 		$encrypted = base64_decode($encrypted);
167
-		if(!$encrypted)
168
-			throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.');
169
-		if(strlen($encrypted) < self::ENCRYPTION_IV_SIZE) 
170
-			throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.');
171
+		if(!$encrypted) {
172
+					throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.');
173
+		}
174
+		if(strlen($encrypted) < self::ENCRYPTION_IV_SIZE) {
175
+					throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.');
176
+		}
171 177
 		$iv_dec = substr($encrypted, 0, self::ENCRYPTION_IV_SIZE);
172 178
 		$encrypted = substr($encrypted, self::ENCRYPTION_IV_SIZE);
173 179
 		$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encrypted, MCRYPT_MODE_CBC, $iv_dec);
@@ -208,7 +214,9 @@  discard block
 block discarded – undo
208 214
 	 * @return boolean True if path valid
209 215
 	 */
210 216
 	public static function isValidPath($filename, $acceptfolder = FALSE) {		
211
-		if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true;
217
+		if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) {
218
+			return true;
219
+		}
212 220
 		return false;
213 221
 	}
214 222
 	
Please login to merge, or discard this patch.