@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @param integer $num Numerator |
53 | 53 | * @param integer $denom Denominator |
54 | - * @param float $default Default value if denominator null or 0 |
|
55 | - * @return float Result of the safe division |
|
54 | + * @param integer $default Default value if denominator null or 0 |
|
55 | + * @return integer Result of the safe division |
|
56 | 56 | */ |
57 | 57 | public static function safeDivision($num, $denom, $default = 0) { |
58 | 58 | if($denom && $denom!=0){ |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @param int $num Numerator |
68 | 68 | * @param int $denom Denominator |
69 | - * @param float $default Default value if denominator null or 0 |
|
70 | - * @return float Percentage |
|
69 | + * @param integer $default Default value if denominator null or 0 |
|
70 | + * @return integer Percentage |
|
71 | 71 | */ |
72 | 72 | public static function getPercentage($num, $denom, $default = 0){ |
73 | 73 | return 100 * self::safeDivision($num, $denom, $default); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @param string $file The image to resize |
80 | 80 | * @param int $target The final max width/height |
81 | - * @return array array of ($width, $height). One of them must be $target |
|
81 | + * @return integer[] array of ($width, $height). One of them must be $target |
|
82 | 82 | */ |
83 | 83 | static public function getResizedImageSize($file, $target=25){ |
84 | 84 | list($width, $height, $type, $attr) = getimagesize($file); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * Returns the generation associated with a Sosa number |
234 | 234 | * |
235 | 235 | * @param int $sosa Sosa number |
236 | - * @return number |
|
236 | + * @return integer |
|
237 | 237 | */ |
238 | 238 | public static function getGeneration($sosa){ |
239 | 239 | return(int)log($sosa, 2)+1; |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * Returns whether the image type is supported by the system, and if so, return the standardised type |
247 | 247 | * |
248 | 248 | * @param string $reqtype Extension to test |
249 | - * @return boolean|string Is supported? |
|
249 | + * @return false|string Is supported? |
|
250 | 250 | */ |
251 | 251 | public static function isImageTypeSupported($reqtype) { |
252 | 252 | $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); |
@@ -114,16 +114,18 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |