Completed
Pull Request — master (#56)
by
unknown
03:56
created
src/bulletproof.php 2 patches
Braces   +20 added lines, -39 removed lines patch added patch discarded remove patch
@@ -102,8 +102,7 @@  discard block
 block discarded – undo
102 102
     /**
103 103
      * @param array $_files represents the $_FILES array passed as dependancy
104 104
      */
105
-    public function __construct(array $_files = [])
106
-    {
105
+    public function __construct(array $_files = []) {
107 106
         $this->_files = $_files;
108 107
     }
109 108
 
@@ -114,8 +113,7 @@  discard block
 block discarded – undo
114 113
      *
115 114
      * @return bool|string
116 115
      */
117
-    protected function getImageMime($tmp_name)
118
-    {
116
+    protected function getImageMime($tmp_name) {
119 117
         if (isset($this->imageMimes[exif_imagetype($tmp_name)])) {
120 118
             return $this->imageMimes [exif_imagetype($tmp_name)];
121 119
         }
@@ -137,8 +135,7 @@  discard block
 block discarded – undo
137 135
      *
138 136
      * @return bool|mixed
139 137
      */
140
-    public function offsetGet($offset)
141
-    {
138
+    public function offsetGet($offset) {
142 139
         if ($offset == "error") {
143 140
             return $this->error;
144 141
         }
@@ -158,8 +155,7 @@  discard block
 block discarded – undo
158 155
      *
159 156
      * @return $this
160 157
      */
161
-    public function setName($isNameProvided = null)
162
-    {
158
+    public function setName($isNameProvided = null) {
163 159
         if ($isNameProvided) {
164 160
             $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING);
165 161
         }
@@ -174,8 +170,7 @@  discard block
 block discarded – undo
174 170
      *
175 171
      * @return $this
176 172
      */
177
-    public function setMime(array $fileTypes)
178
-    {
173
+    public function setMime(array $fileTypes) {
179 174
         $this->mimeTypes = $fileTypes;
180 175
         return $this;
181 176
     }
@@ -188,8 +183,7 @@  discard block
 block discarded – undo
188 183
      *
189 184
      * @return $this
190 185
      */
191
-    public function setSize($min, $max)
192
-    {
186
+    public function setSize($min, $max) {
193 187
         $this->size = array($min, $max);
194 188
         return $this;
195 189
     }
@@ -202,8 +196,7 @@  discard block
 block discarded – undo
202 196
      *
203 197
      * @return $this
204 198
      */
205
-    public function setLocation($dir = "bulletproof", $permission = 0666)
206
-    {
199
+    public function setLocation($dir = "bulletproof", $permission = 0666) {
207 200
         if (!file_exists($dir) && !is_dir($dir) && !$this->location) {
208 201
             $createFolder = @mkdir("" . $dir, (int) $permission, true);
209 202
             if (!$createFolder) {
@@ -224,8 +217,7 @@  discard block
 block discarded – undo
224 217
      *
225 218
      * @return $this
226 219
      */
227
-    public function setDimension($maxWidth, $maxHeight)
228
-    {
220
+    public function setDimension($maxWidth, $maxHeight) {
229 221
         $this->dimensions = array($maxWidth, $maxHeight);
230 222
         return $this;
231 223
     }
@@ -235,8 +227,7 @@  discard block
 block discarded – undo
235 227
      *
236 228
      * @return string
237 229
      */
238
-    public function getName()
239
-    {
230
+    public function getName() {
240 231
         if (!$this->name) {
241 232
            return  uniqid(true) . "_" . str_shuffle(implode(range("e", "q")));
242 233
         }
@@ -249,8 +240,7 @@  discard block
 block discarded – undo
249 240
      *
250 241
      * @return string
251 242
      */
252
-    public function getFullPath()
253
-    {
243
+    public function getFullPath() {
254 244
         $this->fullPath = $this->location . "/" . $this->name . "." . $this->mime;
255 245
         return $this->fullPath;
256 246
     }
@@ -260,8 +250,7 @@  discard block
 block discarded – undo
260 250
      *
261 251
      * @return int
262 252
      */
263
-    public function getSize()
264
-    {
253
+    public function getSize() {
265 254
         return (int) $this->_files["size"];
266 255
     }
267 256
 
@@ -270,8 +259,7 @@  discard block
 block discarded – undo
270 259
      *
271 260
      * @return int
272 261
      */
273
-    public function getHeight()
274
-    {
262
+    public function getHeight() {
275 263
         if ($this->height != null) {
276 264
             return $this->height;
277 265
         }
@@ -285,8 +273,7 @@  discard block
 block discarded – undo
285 273
      *
286 274
      * @return int
287 275
      */
288
-    public function getWidth()
289
-    {
276
+    public function getWidth() {
290 277
         if ($this->width != null) {
291 278
             return $this->width;
292 279
         }
@@ -300,8 +287,7 @@  discard block
 block discarded – undo
300 287
      *
301 288
      * @return string
302 289
      */
303
-    public function getLocation()
304
-    {
290
+    public function getLocation() {
305 291
         if(!$this->location){
306 292
             $this->setLocation(); 
307 293
         }
@@ -314,8 +300,7 @@  discard block
 block discarded – undo
314 300
      *
315 301
      * @return string
316 302
      */
317
-    public function getJson()
318
-    {
303
+    public function getJson() {
319 304
         return json_encode($this->serialize);
320 305
     }
321 306
 
@@ -324,8 +309,7 @@  discard block
 block discarded – undo
324 309
      *
325 310
      * @return string
326 311
      */
327
-    public function getMime()
328
-    {
312
+    public function getMime() {
329 313
         return $this->mime;
330 314
     }
331 315
 
@@ -334,7 +318,7 @@  discard block
 block discarded – undo
334 318
      *
335 319
      * @return string|bool
336 320
      */
337
-    public function getError(){
321
+    public function getError() {
338 322
         return $this->error;
339 323
     }
340 324
 
@@ -343,8 +327,7 @@  discard block
 block discarded – undo
343 327
      *
344 328
      * @param $e int error constant
345 329
      */
346
-    protected function uploadErrors($e)
347
-    {
330
+    protected function uploadErrors($e) {
348 331
         $errors = array(
349 332
             UPLOAD_ERR_OK           => 0,
350 333
             UPLOAD_ERR_INI_SIZE     => Image::IMAGE_ERR_INI_SIZE,
@@ -364,8 +347,7 @@  discard block
 block discarded – undo
364 347
      *
365 348
      * @return $this|bool
366 349
      */
367
-    public function upload()
368
-    {
350
+    public function upload() {
369 351
         /* modify variable names for convenience */
370 352
         $image = $this; 
371 353
         $files = $this->_files;
@@ -448,8 +430,7 @@  discard block
 block discarded – undo
448 430
      *
449 431
      * @return bool
450 432
      */
451
-    public function moveUploadedFile($tmp_name, $destination)
452
-    {
433
+    public function moveUploadedFile($tmp_name, $destination) {
453 434
         return move_uploaded_file($tmp_name, $destination);
454 435
     }
455 436
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
      * array offset \ArrayAccess
113 113
      * unused
114 114
      */
115
-    public function offsetSet($offset, $value){}
116
-    public function offsetExists($offset){}
117
-    public function offsetUnset($offset){}
115
+    public function offsetSet($offset, $value) {}
116
+    public function offsetExists($offset) {}
117
+    public function offsetUnset($offset) {}
118 118
 
119 119
     /**
120 120
      * Gets array value \ArrayAccess
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
     public function setLocation($dir = "bulletproof", $permission = 0666)
192 192
     {
193 193
         if (!file_exists($dir) && !is_dir($dir) && !$this->location) {
194
-            $createFolder = @mkdir("" . $dir, (int) $permission, true);
194
+            $createFolder = @mkdir("".$dir, (int) $permission, true);
195 195
             if (!$createFolder) {
196
-                $this->error = "Folder " . $dir . " could not be created";
196
+                $this->error = "Folder ".$dir." could not be created";
197 197
                 return;
198 198
             }
199 199
         }
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
     public function getName()
225 225
     {
226 226
         if (!$this->name) {
227
-           return  uniqid(true) . "_" . str_shuffle(implode(range("e", "q")));
227
+           return  uniqid(true)."_".str_shuffle(implode(range("e", "q")));
228 228
         }
229 229
 
230 230
         return $this->name;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
      */
238 238
     public function getFullPath()
239 239
     {
240
-        $this->fullPath = $this->location . "/" . $this->name . "." . $this->mime;
240
+        $this->fullPath = $this->location."/".$this->name.".".$this->mime;
241 241
         return $this->fullPath;
242 242
     }
243 243
 
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
      */
289 289
     public function getLocation()
290 290
     {
291
-        if(!$this->location){
291
+        if (!$this->location) {
292 292
             $this->setLocation(); 
293 293
         }
294 294
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      *
321 321
      * @return string|bool
322 322
      */
323
-    public function getError(){
323
+    public function getError() {
324 324
         return $this->error != "" ? $this->error : false;
325 325
     }
326 326
 
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
         list($minSize, $maxSize) = $image->size;
367 367
 
368 368
         /* check for common upload errors */
369
-        if($image->error = $image->uploadErrors($files["error"])){
370
-            return ;
369
+        if ($image->error = $image->uploadErrors($files["error"])) {
370
+            return;
371 371
         }
372 372
 
373 373
         /* check image for valid mime types and return mime */
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
         if (!in_array($image->mime, $image->mimeTypes)) {
378 378
             $ext = implode(", ", $image->mimeTypes);
379 379
             $image->error = "Invalid File! Only ($ext) image types are allowed";
380
-            return ;
380
+            return;
381 381
         }     
382 382
 
383 383
         /* check image size based on the settings */
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
             $min = intval($minSize / 1000) ?: 1; $max = intval($maxSize / 1000);
386 386
             
387 387
             $image->error = "Image size should be atleast more than min: $min and less than max: $max kb";
388
-            return ;
388
+            return;
389 389
         }
390 390
 
391 391
         /* check image dimension */
@@ -393,16 +393,16 @@  discard block
 block discarded – undo
393 393
 
394 394
         if ($image->height > $allowedHeight || $image->width > $allowedWidth) {
395 395
             $image->error = "Image height/width should be less than ' $allowedHeight \ $allowedWidth ' pixels";
396
-            return ;
396
+            return;
397 397
         }
398 398
 
399
-        if($image->height < 4 || $image->width < 4){
399
+        if ($image->height < 4 || $image->width < 4) {
400 400
             $image->error = "Invalid! Image height/width is too small or maybe corrupted"; 
401
-            return ;
401
+            return;
402 402
         }
403 403
  
404 404
         /* set and get folder name */
405
-        $image->fullPath = $image->location. "/" . $image->name . "." . $image->mime;
405
+        $image->fullPath = $image->location."/".$image->name.".".$image->mime;
406 406
 
407 407
         /* gather image info for json storage */ 
408 408
         $image->serialize = array(
Please login to merge, or discard this patch.
src/utils/func.image-crop.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 namespace Bulletproof;
11 11
 
12
- function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight){
12
+ function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight) {
13 13
 
14 14
     switch ($mimeType) {
15 15
         case "jpg":
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     // Can't crop to a bigger size, ex: 
38 38
     // an image with 100X100 can not be cropped to 200X200. Image can only be cropped to smaller size.
39 39
     if ($widthTrim < 0 && $heightTrim < 0) {
40
-        return ;
40
+        return;
41 41
     }
42 42
 
43 43
     $temp = imagecreatetruecolor($newWidth, $newHeight);
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
  */
10 10
 namespace Bulletproof;
11 11
 
12
- function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight){
12
+ function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight) {
13 13
 
14 14
     switch ($mimeType) {
15 15
         case "jpg":
Please login to merge, or discard this patch.
src/utils/func.image-resize.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
  */
10 10
 namespace Bulletproof;
11 11
 
12
-function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE){           
12
+function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE) {           
13 13
     
14 14
     // First, calculate the height.
15 15
     $height = intval($newWidth / $imgWidth * $imgHeight);
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
  */
10 10
 namespace Bulletproof;
11 11
 
12
-function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE){           
12
+function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE) {
13 13
     
14 14
     // First, calculate the height.
15 15
     $height = intval($newWidth / $imgWidth * $imgHeight);
Please login to merge, or discard this patch.
src/utils/func.image-watermark.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
  */
10 10
 namespace Bulletproof;
11 11
 
12
- function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center"){
12
+ function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center") {
13 13
 
14 14
     // Calculate the watermark position
15 15
     switch ($position) {
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
  */
10 10
 namespace Bulletproof;
11 11
 
12
- function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center"){
12
+ function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center") {
13 13
 
14 14
     // Calculate the watermark position
15 15
     switch ($position) {
Please login to merge, or discard this patch.