@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | * @param mixed $value |
| 111 | 111 | * @return null |
| 112 | 112 | */ |
| 113 | - public function offsetSet($offset, $value){}
|
|
| 113 | + public function offsetSet($offset, $value) {}
|
|
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | 116 | * @param mixed $offset |
| 117 | 117 | * @return null |
| 118 | 118 | */ |
| 119 | - public function offsetExists($offset){}
|
|
| 119 | + public function offsetExists($offset) {}
|
|
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | 122 | * @param mixed $offset |
| 123 | 123 | * @return null |
| 124 | 124 | */ |
| 125 | - public function offsetUnset($offset){}
|
|
| 125 | + public function offsetUnset($offset) {}
|
|
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | 128 | * Gets array value \ArrayAccess |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $this->_files = $this->_files[$offset]; |
| 147 | 147 | |
| 148 | 148 | // check for common upload errors |
| 149 | - if(isset($this->_files['error'])){
|
|
| 149 | + if (isset($this->_files['error'])) {
|
|
| 150 | 150 | $this->error = $this->commonUploadErrors[$this->_files['error']]; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | public function getFullPath() |
| 176 | 176 | {
|
| 177 | - return $this->fullPath = $this->getLocation() . '/' . $this->getName() . '.' . $this->getMime(); |
|
| 177 | + return $this->fullPath = $this->getLocation().'/'.$this->getName().'.'.$this->getMime(); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | public function getJson() |
| 210 | 210 | {
|
| 211 | 211 | /* gather image info for json storage */ |
| 212 | - return json_encode ( |
|
| 212 | + return json_encode( |
|
| 213 | 213 | array( |
| 214 | 214 | 'name' => $this->name, |
| 215 | 215 | 'mime' => $this->mime, |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | public function getName() |
| 285 | 285 | {
|
| 286 | 286 | if (!$this->name) {
|
| 287 | - return uniqid('', true) . '_' . str_shuffle(implode(range('e', 'q')));
|
|
| 287 | + return uniqid('', true).'_'.str_shuffle(implode(range('e', 'q')));
|
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | return $this->name; |
@@ -373,15 +373,15 @@ discard block |
||
| 373 | 373 | {
|
| 374 | 374 | $isDirectoryValid = $this->isDirectoryValid($dir); |
| 375 | 375 | |
| 376 | - if(!$isDirectoryValid){
|
|
| 377 | - $this->error = 'Can not create a folder \'' . $dir . '\', please check your dir permission issues'; |
|
| 376 | + if (!$isDirectoryValid) {
|
|
| 377 | + $this->error = 'Can not create a folder \''.$dir.'\', please check your dir permission issues'; |
|
| 378 | 378 | return false; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - $create = !is_dir($dir) ? @mkdir('' . $dir, (int) $permission, true) : true;
|
|
| 381 | + $create = !is_dir($dir) ? @mkdir(''.$dir, (int) $permission, true) : true;
|
|
| 382 | 382 | |
| 383 | 383 | if (!$create) {
|
| 384 | - $this->error = 'Error! Folder ' . $dir . ' could not be created'; |
|
| 384 | + $this->error = 'Error! Folder '.$dir.' could not be created'; |
|
| 385 | 385 | return false; |
| 386 | 386 | } |
| 387 | 387 | |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | if ($files['size'] < $minSize || $files['size'] > $maxSize) {
|
| 427 | 427 | $min = intval($minSize / 1000) ?: 1; |
| 428 | 428 | $max = intval($maxSize / 1000) ?: 1; |
| 429 | - $image->error = 'Image size should be at least ' . $min . ' KB, and no more than ' . $max . ' KB'; |
|
| 429 | + $image->error = 'Image size should be at least '.$min.' KB, and no more than '.$max.' KB'; |
|
| 430 | 430 | return false; |
| 431 | 431 | } |
| 432 | 432 | |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | list($allowedWidth, $allowedHeight) = $image->dimensions; |
| 435 | 435 | |
| 436 | 436 | if ($image->height > $allowedHeight || $image->width > $allowedWidth) {
|
| 437 | - $image->error = 'Image height/width should be less than ' . $allowedHeight . '/' . $allowedWidth . ' pixels'; |
|
| 437 | + $image->error = 'Image height/width should be less than '.$allowedHeight.'/'.$allowedWidth.' pixels'; |
|
| 438 | 438 | return false; |
| 439 | 439 | } |
| 440 | 440 | |
@@ -94,8 +94,7 @@ discard block |
||
| 94 | 94 | /** |
| 95 | 95 | * @param array $_files represents the $_FILES array passed as dependency |
| 96 | 96 | */ |
| 97 | - public function __construct(array $_files = array()) |
|
| 98 | - {
|
|
| 97 | + public function __construct(array $_files = array()) { |
|
| 99 | 98 | /* check if php_exif is enabled */ |
| 100 | 99 | if (!function_exists('exif_imagetype')) {
|
| 101 | 100 | $this->error = 'Function \'exif_imagetype\' Not found. Please enable \'php_exif\' in your PHP.ini'; |
@@ -131,8 +130,7 @@ discard block |
||
| 131 | 130 | * |
| 132 | 131 | * @return string|boolean |
| 133 | 132 | */ |
| 134 | - public function offsetGet($offset) |
|
| 135 | - {
|
|
| 133 | + public function offsetGet($offset) { |
|
| 136 | 134 | // return error if requested |
| 137 | 135 | if ($offset == 'error') {
|
| 138 | 136 | return $this->error; |
@@ -161,8 +159,7 @@ discard block |
||
| 161 | 159 | * |
| 162 | 160 | * @return $this |
| 163 | 161 | */ |
| 164 | - public function setDimension($maxWidth, $maxHeight) |
|
| 165 | - {
|
|
| 162 | + public function setDimension($maxWidth, $maxHeight) { |
|
| 166 | 163 | $this->dimensions = array($maxWidth, $maxHeight); |
| 167 | 164 | return $this; |
| 168 | 165 | } |
@@ -172,8 +169,7 @@ discard block |
||
| 172 | 169 | * |
| 173 | 170 | * @return string |
| 174 | 171 | */ |
| 175 | - public function getFullPath() |
|
| 176 | - {
|
|
| 172 | + public function getFullPath() { |
|
| 177 | 173 | return $this->fullPath = $this->getLocation() . '/' . $this->getName() . '.' . $this->getMime(); |
| 178 | 174 | } |
| 179 | 175 | |
@@ -182,8 +178,7 @@ discard block |
||
| 182 | 178 | * |
| 183 | 179 | * @return int |
| 184 | 180 | */ |
| 185 | - public function getSize() |
|
| 186 | - {
|
|
| 181 | + public function getSize() { |
|
| 187 | 182 | return (int) $this->_files['size']; |
| 188 | 183 | } |
| 189 | 184 | |
@@ -195,8 +190,7 @@ discard block |
||
| 195 | 190 | * |
| 196 | 191 | * @return $this |
| 197 | 192 | */ |
| 198 | - public function setSize($min, $max) |
|
| 199 | - {
|
|
| 193 | + public function setSize($min, $max) { |
|
| 200 | 194 | $this->size = array($min, $max); |
| 201 | 195 | return $this; |
| 202 | 196 | } |
@@ -206,8 +200,7 @@ discard block |
||
| 206 | 200 | * |
| 207 | 201 | * @return string |
| 208 | 202 | */ |
| 209 | - public function getJson() |
|
| 210 | - {
|
|
| 203 | + public function getJson() { |
|
| 211 | 204 | /* gather image info for json storage */ |
| 212 | 205 | return json_encode ( |
| 213 | 206 | array( |
@@ -227,8 +220,7 @@ discard block |
||
| 227 | 220 | * |
| 228 | 221 | * @return null|string |
| 229 | 222 | */ |
| 230 | - public function getMime() |
|
| 231 | - {
|
|
| 223 | + public function getMime() { |
|
| 232 | 224 | if (!$this->mime) {
|
| 233 | 225 | return $this->getImageMime($this->_files['tmp_name']); |
| 234 | 226 | } |
@@ -242,8 +234,7 @@ discard block |
||
| 242 | 234 | * |
| 243 | 235 | * @return $this |
| 244 | 236 | */ |
| 245 | - public function setMime(array $fileTypes) |
|
| 246 | - {
|
|
| 237 | + public function setMime(array $fileTypes) { |
|
| 247 | 238 | $this->mimeTypes = $fileTypes; |
| 248 | 239 | return $this; |
| 249 | 240 | } |
@@ -255,8 +246,7 @@ discard block |
||
| 255 | 246 | * |
| 256 | 247 | * @return null|string |
| 257 | 248 | */ |
| 258 | - protected function getImageMime($tmp_name) |
|
| 259 | - {
|
|
| 249 | + protected function getImageMime($tmp_name) { |
|
| 260 | 250 | $mime = @ $this->acceptedMimes[exif_imagetype($tmp_name)]; |
| 261 | 251 | |
| 262 | 252 | if (!$mime) {
|
@@ -271,8 +261,7 @@ discard block |
||
| 271 | 261 | * |
| 272 | 262 | * @return string|false |
| 273 | 263 | */ |
| 274 | - public function getError() |
|
| 275 | - {
|
|
| 264 | + public function getError() { |
|
| 276 | 265 | return $this->error != '' ? $this->error : false; |
| 277 | 266 | } |
| 278 | 267 | |
@@ -281,8 +270,7 @@ discard block |
||
| 281 | 270 | * |
| 282 | 271 | * @return string |
| 283 | 272 | */ |
| 284 | - public function getName() |
|
| 285 | - {
|
|
| 273 | + public function getName() { |
|
| 286 | 274 | if (!$this->name) {
|
| 287 | 275 | return uniqid('', true) . '_' . str_shuffle(implode(range('e', 'q')));
|
| 288 | 276 | } |
@@ -296,8 +284,7 @@ discard block |
||
| 296 | 284 | * @param null $isNameProvided |
| 297 | 285 | * @return $this |
| 298 | 286 | */ |
| 299 | - public function setName($isNameProvided = null) |
|
| 300 | - {
|
|
| 287 | + public function setName($isNameProvided = null) { |
|
| 301 | 288 | if ($isNameProvided) {
|
| 302 | 289 | $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); |
| 303 | 290 | } |
@@ -310,8 +297,7 @@ discard block |
||
| 310 | 297 | * |
| 311 | 298 | * @return int |
| 312 | 299 | */ |
| 313 | - public function getWidth() |
|
| 314 | - {
|
|
| 300 | + public function getWidth() { |
|
| 315 | 301 | if ($this->width != null) {
|
| 316 | 302 | return $this->width; |
| 317 | 303 | } |
@@ -325,8 +311,7 @@ discard block |
||
| 325 | 311 | * |
| 326 | 312 | * @return int |
| 327 | 313 | */ |
| 328 | - public function getHeight() |
|
| 329 | - {
|
|
| 314 | + public function getHeight() { |
|
| 330 | 315 | if ($this->height != null) {
|
| 331 | 316 | return $this->height; |
| 332 | 317 | } |
@@ -340,8 +325,7 @@ discard block |
||
| 340 | 325 | * |
| 341 | 326 | * @return string |
| 342 | 327 | */ |
| 343 | - public function getLocation() |
|
| 344 | - {
|
|
| 328 | + public function getLocation() { |
|
| 345 | 329 | if (!$this->location) {
|
| 346 | 330 | $this->setLocation(); |
| 347 | 331 | } |
@@ -356,8 +340,7 @@ discard block |
||
| 356 | 340 | * |
| 357 | 341 | * @return bool |
| 358 | 342 | */ |
| 359 | - private function isDirectoryValid($dir) |
|
| 360 | - {
|
|
| 343 | + private function isDirectoryValid($dir) { |
|
| 361 | 344 | return !file_exists($dir) && !is_dir($dir) || is_writable($dir); |
| 362 | 345 | } |
| 363 | 346 | |
@@ -369,8 +352,7 @@ discard block |
||
| 369 | 352 | * |
| 370 | 353 | * @return $this |
| 371 | 354 | */ |
| 372 | - public function setLocation($dir = 'bulletproof', $permission = 0666) |
|
| 373 | - {
|
|
| 355 | + public function setLocation($dir = 'bulletproof', $permission = 0666) { |
|
| 374 | 356 | $isDirectoryValid = $this->isDirectoryValid($dir); |
| 375 | 357 | |
| 376 | 358 | if(!$isDirectoryValid){
|
@@ -393,8 +375,7 @@ discard block |
||
| 393 | 375 | * This methods validates and uploads the image |
| 394 | 376 | * @return false|Image |
| 395 | 377 | */ |
| 396 | - public function upload() |
|
| 397 | - {
|
|
| 378 | + public function upload() { |
|
| 398 | 379 | /* modify variable names for convenience */ |
| 399 | 380 | $image = $this; |
| 400 | 381 | $files = $this->_files; |
@@ -463,8 +444,7 @@ discard block |
||
| 463 | 444 | * |
| 464 | 445 | * @return bool |
| 465 | 446 | */ |
| 466 | - public function moveUploadedFile($tmp_name, $destination) |
|
| 467 | - {
|
|
| 447 | + public function moveUploadedFile($tmp_name, $destination) { |
|
| 468 | 448 | return move_uploaded_file($tmp_name, $destination); |
| 469 | 449 | } |
| 470 | 450 | } |
| 471 | 451 | \ No newline at end of file |