@@ -133,8 +133,7 @@ discard block |
||
| 133 | 133 | /** |
| 134 | 134 | * @param array $_files represents the $_FILES array passed as dependency |
| 135 | 135 | */ |
| 136 | - public function __construct(array $_files = array()) |
|
| 137 | - { |
|
| 136 | + public function __construct(array $_files = array()) { |
|
| 138 | 137 | if (!function_exists('exif_imagetype')) { |
| 139 | 138 | $this->error = $this->commonUploadErrors[$this->language]['ERROR_01']; |
| 140 | 139 | } |
@@ -171,8 +170,7 @@ discard block |
||
| 171 | 170 | * |
| 172 | 171 | * @return string|bool |
| 173 | 172 | */ |
| 174 | - public function offsetGet($offset) |
|
| 175 | - { |
|
| 173 | + public function offsetGet($offset) { |
|
| 176 | 174 | // return false if $_FILES['key'] isn't found |
| 177 | 175 | if (!isset($this->_files[$offset])) { |
| 178 | 176 | $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_02'], $offset); |
@@ -197,8 +195,7 @@ discard block |
||
| 197 | 195 | * |
| 198 | 196 | * @return $this |
| 199 | 197 | */ |
| 200 | - public function setDimension($maxWidth, $maxHeight) |
|
| 201 | - { |
|
| 198 | + public function setDimension($maxWidth, $maxHeight) { |
|
| 202 | 199 | if ( (int) $maxWidth && (int) $maxHeight) { |
| 203 | 200 | $this->dimensions = array($maxWidth, $maxHeight); |
| 204 | 201 | } else { |
@@ -213,8 +210,7 @@ discard block |
||
| 213 | 210 | * |
| 214 | 211 | * @return string |
| 215 | 212 | */ |
| 216 | - public function getFullPath() |
|
| 217 | - { |
|
| 213 | + public function getFullPath() { |
|
| 218 | 214 | return $this->fullPath = $this->getLocation().'/'.$this->getName().'.'.$this->getMime(); |
| 219 | 215 | } |
| 220 | 216 | |
@@ -225,8 +221,7 @@ discard block |
||
| 225 | 221 | * |
| 226 | 222 | * @return $this |
| 227 | 223 | */ |
| 228 | - public function setLanguage($lang) |
|
| 229 | - { |
|
| 224 | + public function setLanguage($lang) { |
|
| 230 | 225 | if (isset($this->commonUploadErrors[$lang])) { |
| 231 | 226 | $this->language = $lang; |
| 232 | 227 | } else { |
@@ -241,8 +236,7 @@ discard block |
||
| 241 | 236 | * |
| 242 | 237 | * @return int |
| 243 | 238 | */ |
| 244 | - public function getSize() |
|
| 245 | - { |
|
| 239 | + public function getSize() { |
|
| 246 | 240 | return (int) $this->_files['size']; |
| 247 | 241 | } |
| 248 | 242 | |
@@ -254,8 +248,7 @@ discard block |
||
| 254 | 248 | * |
| 255 | 249 | * @return $this |
| 256 | 250 | */ |
| 257 | - public function setSize($min, $max) |
|
| 258 | - { |
|
| 251 | + public function setSize($min, $max) { |
|
| 259 | 252 | $this->size = array($min, $max); |
| 260 | 253 | return $this; |
| 261 | 254 | } |
@@ -265,8 +258,7 @@ discard block |
||
| 265 | 258 | * |
| 266 | 259 | * @return string |
| 267 | 260 | */ |
| 268 | - public function getJson() |
|
| 269 | - { |
|
| 261 | + public function getJson() { |
|
| 270 | 262 | return json_encode( |
| 271 | 263 | array( |
| 272 | 264 | 'name' => $this->name, |
@@ -285,8 +277,7 @@ discard block |
||
| 285 | 277 | * |
| 286 | 278 | * @return null|string |
| 287 | 279 | */ |
| 288 | - public function getMime() |
|
| 289 | - { |
|
| 280 | + public function getMime() { |
|
| 290 | 281 | if (!$this->mime) { |
| 291 | 282 | $this->mime = $this->getImageMime($this->_files['tmp_name']); |
| 292 | 283 | } |
@@ -301,8 +292,7 @@ discard block |
||
| 301 | 292 | * |
| 302 | 293 | * @return $this |
| 303 | 294 | */ |
| 304 | - public function setMime(array $fileTypes) |
|
| 305 | - { |
|
| 295 | + public function setMime(array $fileTypes) { |
|
| 306 | 296 | $this->mimeTypes = $fileTypes; |
| 307 | 297 | return $this; |
| 308 | 298 | } |
@@ -314,8 +304,7 @@ discard block |
||
| 314 | 304 | * |
| 315 | 305 | * @return null|string |
| 316 | 306 | */ |
| 317 | - protected function getImageMime($tmp_name) |
|
| 318 | - { |
|
| 307 | + protected function getImageMime($tmp_name) { |
|
| 319 | 308 | $this->mime = @$this->acceptedMimes[exif_imagetype($tmp_name)]; |
| 320 | 309 | if (!$this->mime) { |
| 321 | 310 | return null; |
@@ -329,8 +318,7 @@ discard block |
||
| 329 | 318 | * |
| 330 | 319 | * @return string |
| 331 | 320 | */ |
| 332 | - public function getError() |
|
| 333 | - { |
|
| 321 | + public function getError() { |
|
| 334 | 322 | return $this->error; |
| 335 | 323 | } |
| 336 | 324 | |
@@ -339,8 +327,7 @@ discard block |
||
| 339 | 327 | * |
| 340 | 328 | * @return string |
| 341 | 329 | */ |
| 342 | - public function getName() |
|
| 343 | - { |
|
| 330 | + public function getName() { |
|
| 344 | 331 | if (!$this->name) { |
| 345 | 332 | $this->name = uniqid('', true).'_'.str_shuffle(implode(range('e', 'q'))); |
| 346 | 333 | } |
@@ -355,8 +342,7 @@ discard block |
||
| 355 | 342 | * |
| 356 | 343 | * @return $this |
| 357 | 344 | */ |
| 358 | - public function setName($isNameProvided = null) |
|
| 359 | - { |
|
| 345 | + public function setName($isNameProvided = null) { |
|
| 360 | 346 | if ($isNameProvided) { |
| 361 | 347 | $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); |
| 362 | 348 | } |
@@ -369,8 +355,7 @@ discard block |
||
| 369 | 355 | * |
| 370 | 356 | * @return int |
| 371 | 357 | */ |
| 372 | - public function getWidth() |
|
| 373 | - { |
|
| 358 | + public function getWidth() { |
|
| 374 | 359 | if ($this->width != null) { |
| 375 | 360 | return $this->width; |
| 376 | 361 | } |
@@ -385,8 +370,7 @@ discard block |
||
| 385 | 370 | * |
| 386 | 371 | * @return int |
| 387 | 372 | */ |
| 388 | - public function getHeight() |
|
| 389 | - { |
|
| 373 | + public function getHeight() { |
|
| 390 | 374 | if ($this->height != null) { |
| 391 | 375 | return $this->height; |
| 392 | 376 | } |
@@ -401,8 +385,7 @@ discard block |
||
| 401 | 385 | * |
| 402 | 386 | * @return string |
| 403 | 387 | */ |
| 404 | - public function getLocation() |
|
| 405 | - { |
|
| 388 | + public function getLocation() { |
|
| 406 | 389 | if (!$this->location) { |
| 407 | 390 | $this->setLocation(); |
| 408 | 391 | } |
@@ -417,8 +400,7 @@ discard block |
||
| 417 | 400 | * |
| 418 | 401 | * @return bool |
| 419 | 402 | */ |
| 420 | - private function isDirectoryValid($dir) |
|
| 421 | - { |
|
| 403 | + private function isDirectoryValid($dir) { |
|
| 422 | 404 | return !file_exists($dir) && !is_dir($dir) || is_writable($dir); |
| 423 | 405 | } |
| 424 | 406 | |
@@ -430,8 +412,7 @@ discard block |
||
| 430 | 412 | * |
| 431 | 413 | * @return $this |
| 432 | 414 | */ |
| 433 | - public function setLocation($dir = 'bulletproof', $permission = 0666) |
|
| 434 | - { |
|
| 415 | + public function setLocation($dir = 'bulletproof', $permission = 0666) { |
|
| 435 | 416 | $isDirectoryValid = $this->isDirectoryValid($dir); |
| 436 | 417 | |
| 437 | 418 | if (!$isDirectoryValid) { |
@@ -456,8 +437,7 @@ discard block |
||
| 456 | 437 | * |
| 457 | 438 | * @return boolean |
| 458 | 439 | */ |
| 459 | - protected function contraintsValidator() |
|
| 460 | - { |
|
| 440 | + protected function contraintsValidator() { |
|
| 461 | 441 | /* check image for valid mime types and return mime */ |
| 462 | 442 | $this->getImageMime($this->_files['tmp_name']); |
| 463 | 443 | /* validate image mime type */ |
@@ -495,8 +475,7 @@ discard block |
||
| 495 | 475 | * |
| 496 | 476 | * @return false|Image |
| 497 | 477 | */ |
| 498 | - public function upload() |
|
| 499 | - { |
|
| 478 | + public function upload() { |
|
| 500 | 479 | if ($this->error !== '') { |
| 501 | 480 | return false; |
| 502 | 481 | } |
@@ -516,8 +495,7 @@ discard block |
||
| 516 | 495 | * |
| 517 | 496 | * @return bool |
| 518 | 497 | */ |
| 519 | - protected function isSaved($tmp_name, $destination) |
|
| 520 | - { |
|
| 498 | + protected function isSaved($tmp_name, $destination) { |
|
| 521 | 499 | return move_uploaded_file($tmp_name, $destination); |
| 522 | 500 | } |
| 523 | 501 | } |