@@ -98,8 +98,7 @@ discard block |
||
| 98 | 98 | /** |
| 99 | 99 | * @param array $_files represents the $_FILES array passed as dependency |
| 100 | 100 | */ |
| 101 | - public function __construct(array $_files = array()) |
|
| 102 | - {
|
|
| 101 | + public function __construct(array $_files = array()) { |
|
| 103 | 102 | /* check if php_exif is enabled */ |
| 104 | 103 | if (!function_exists('exif_imagetype')) {
|
| 105 | 104 | $this->error = 'Function \'exif_imagetype\' Not found. Please enable \'php_exif\' in your php.ini'; |
@@ -136,8 +135,7 @@ discard block |
||
| 136 | 135 | * @param mixed $offset |
| 137 | 136 | * @return string|boolean |
| 138 | 137 | */ |
| 139 | - public function offsetGet($offset) |
|
| 140 | - {
|
|
| 138 | + public function offsetGet($offset) { |
|
| 141 | 139 | // return error if requested |
| 142 | 140 | if ($offset == 'error') {
|
| 143 | 141 | return $this->error; |
@@ -167,8 +165,7 @@ discard block |
||
| 167 | 165 | * |
| 168 | 166 | * @return $this |
| 169 | 167 | */ |
| 170 | - public function setDimension($maxWidth, $maxHeight) |
|
| 171 | - {
|
|
| 168 | + public function setDimension($maxWidth, $maxHeight) { |
|
| 172 | 169 | $this->dimensions = array($maxWidth, $maxHeight); |
| 173 | 170 | return $this; |
| 174 | 171 | } |
@@ -178,8 +175,7 @@ discard block |
||
| 178 | 175 | * |
| 179 | 176 | * @return string |
| 180 | 177 | */ |
| 181 | - public function getFullPath() |
|
| 182 | - {
|
|
| 178 | + public function getFullPath() { |
|
| 183 | 179 | return $this->fullPath = $this->getLocation() . '/' . $this->getName() . '.' . $this->getMime(); |
| 184 | 180 | } |
| 185 | 181 | |
@@ -188,8 +184,7 @@ discard block |
||
| 188 | 184 | * |
| 189 | 185 | * @return int |
| 190 | 186 | */ |
| 191 | - public function getSize() |
|
| 192 | - {
|
|
| 187 | + public function getSize() { |
|
| 193 | 188 | return (int) $this->_files['size']; |
| 194 | 189 | } |
| 195 | 190 | |
@@ -201,8 +196,7 @@ discard block |
||
| 201 | 196 | * |
| 202 | 197 | * @return $this |
| 203 | 198 | */ |
| 204 | - public function setSize($min, $max) |
|
| 205 | - {
|
|
| 199 | + public function setSize($min, $max) { |
|
| 206 | 200 | $this->size = array($min, $max); |
| 207 | 201 | return $this; |
| 208 | 202 | } |
@@ -212,8 +206,7 @@ discard block |
||
| 212 | 206 | * |
| 213 | 207 | * @return string |
| 214 | 208 | */ |
| 215 | - public function getJson() |
|
| 216 | - {
|
|
| 209 | + public function getJson() { |
|
| 217 | 210 | return json_encode ( |
| 218 | 211 | array( |
| 219 | 212 | 'name' => $this->name, |
@@ -232,8 +225,7 @@ discard block |
||
| 232 | 225 | * |
| 233 | 226 | * @return null|string |
| 234 | 227 | */ |
| 235 | - public function getMime() |
|
| 236 | - {
|
|
| 228 | + public function getMime() { |
|
| 237 | 229 | if(!$this->mime){
|
| 238 | 230 | $this->mime = $this->getImageMime($this->_files['tmp_name']); |
| 239 | 231 | } |
@@ -248,8 +240,7 @@ discard block |
||
| 248 | 240 | * |
| 249 | 241 | * @return $this |
| 250 | 242 | */ |
| 251 | - public function setMime(array $fileTypes) |
|
| 252 | - {
|
|
| 243 | + public function setMime(array $fileTypes) { |
|
| 253 | 244 | $this->mimeTypes = $fileTypes; |
| 254 | 245 | return $this; |
| 255 | 246 | } |
@@ -261,8 +252,7 @@ discard block |
||
| 261 | 252 | * |
| 262 | 253 | * @return null|string |
| 263 | 254 | */ |
| 264 | - protected function getImageMime($tmp_name) |
|
| 265 | - {
|
|
| 255 | + protected function getImageMime($tmp_name) { |
|
| 266 | 256 | $this->mime = @$this->acceptedMimes[exif_imagetype($tmp_name)]; |
| 267 | 257 | if (!$this->mime) {
|
| 268 | 258 | return null; |
@@ -276,8 +266,7 @@ discard block |
||
| 276 | 266 | * |
| 277 | 267 | * @return string|false |
| 278 | 268 | */ |
| 279 | - public function getError() |
|
| 280 | - {
|
|
| 269 | + public function getError() { |
|
| 281 | 270 | return $this->error; |
| 282 | 271 | } |
| 283 | 272 | |
@@ -286,8 +275,7 @@ discard block |
||
| 286 | 275 | * |
| 287 | 276 | * @return string |
| 288 | 277 | */ |
| 289 | - public function getName() |
|
| 290 | - {
|
|
| 278 | + public function getName() { |
|
| 291 | 279 | if (!$this->name) {
|
| 292 | 280 | $this->name = uniqid('', true) . '_' . str_shuffle(implode(range('e', 'q')));
|
| 293 | 281 | } |
@@ -301,8 +289,7 @@ discard block |
||
| 301 | 289 | * @param null $isNameProvided |
| 302 | 290 | * @return $this |
| 303 | 291 | */ |
| 304 | - public function setName($isNameProvided = null) |
|
| 305 | - {
|
|
| 292 | + public function setName($isNameProvided = null) { |
|
| 306 | 293 | if ($isNameProvided) {
|
| 307 | 294 | $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); |
| 308 | 295 | } |
@@ -315,8 +302,7 @@ discard block |
||
| 315 | 302 | * |
| 316 | 303 | * @return int |
| 317 | 304 | */ |
| 318 | - public function getWidth() |
|
| 319 | - {
|
|
| 305 | + public function getWidth() { |
|
| 320 | 306 | if ($this->width != null) {
|
| 321 | 307 | return $this->width; |
| 322 | 308 | } |
@@ -330,8 +316,7 @@ discard block |
||
| 330 | 316 | * |
| 331 | 317 | * @return int |
| 332 | 318 | */ |
| 333 | - public function getHeight() |
|
| 334 | - {
|
|
| 319 | + public function getHeight() { |
|
| 335 | 320 | if ($this->height != null) {
|
| 336 | 321 | return $this->height; |
| 337 | 322 | } |
@@ -345,8 +330,7 @@ discard block |
||
| 345 | 330 | * |
| 346 | 331 | * @return string |
| 347 | 332 | */ |
| 348 | - public function getLocation() |
|
| 349 | - {
|
|
| 333 | + public function getLocation() { |
|
| 350 | 334 | if (!$this->location) {
|
| 351 | 335 | $this->setLocation(); |
| 352 | 336 | } |
@@ -360,8 +344,7 @@ discard block |
||
| 360 | 344 | * @param $dir string the folder name to check |
| 361 | 345 | * @return bool |
| 362 | 346 | */ |
| 363 | - private function isDirectoryValid($dir) |
|
| 364 | - {
|
|
| 347 | + private function isDirectoryValid($dir) { |
|
| 365 | 348 | return !file_exists($dir) && !is_dir($dir) || is_writable($dir); |
| 366 | 349 | } |
| 367 | 350 | |
@@ -372,8 +355,7 @@ discard block |
||
| 372 | 355 | * @param int $permission chmod permission |
| 373 | 356 | * @return $this |
| 374 | 357 | */ |
| 375 | - public function setLocation($dir = 'bulletproof', $permission = 0666) |
|
| 376 | - {
|
|
| 358 | + public function setLocation($dir = 'bulletproof', $permission = 0666) { |
|
| 377 | 359 | $isDirectoryValid = $this->isDirectoryValid($dir); |
| 378 | 360 | |
| 379 | 361 | if(!$isDirectoryValid){
|
@@ -397,8 +379,7 @@ discard block |
||
| 397 | 379 | * |
| 398 | 380 | * @return false|Image |
| 399 | 381 | */ |
| 400 | - public function upload() |
|
| 401 | - {
|
|
| 382 | + public function upload() { |
|
| 402 | 383 | $image = $this; |
| 403 | 384 | $files = $this->_files; |
| 404 | 385 | |
@@ -458,8 +439,7 @@ discard block |
||
| 458 | 439 | * |
| 459 | 440 | * @return bool |
| 460 | 441 | */ |
| 461 | - public function moveUploadedFile($tmp_name, $destination) |
|
| 462 | - {
|
|
| 442 | + public function moveUploadedFile($tmp_name, $destination) { |
|
| 463 | 443 | if ($image->error === '') {
|
| 464 | 444 | $moveUpload = move_uploaded_file($tmp_name, $destination);; |
| 465 | 445 | if (false !== $moveUpload) {
|