Test Failed
Push — 1.0.0-dev ( 659da7...aa6afc )
by nguereza
04:16
created
core/libraries/Upload.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     *    @package FileUpload
38 38
     *    @version 1.5
39 39
     */
40
-    class Upload{
40
+    class Upload {
41 41
 
42 42
         /**
43 43
         *   Version
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         *    @version    1.0
70 70
         *    @var        array
71 71
         */
72
-        private $file_array    = array();
72
+        private $file_array = array();
73 73
 
74 74
         /**
75 75
         *    If the file you are trying to upload already exists it will
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         *    @version    1.0
120 120
         *    @var        float
121 121
         */
122
-        private $max_file_size= 0.0;
122
+        private $max_file_size = 0.0;
123 123
 
124 124
         /**
125 125
         *    List of allowed mime types
@@ -217,12 +217,12 @@  discard block
 block discarded – undo
217 217
         *    @return    object
218 218
         *    @method    object    __construct
219 219
         */
220
-        public function __construct(){
221
-            $this->logger =& class_loader('Log', 'classes');
220
+        public function __construct() {
221
+            $this->logger = & class_loader('Log', 'classes');
222 222
             $this->logger->setLogger('Library::Upload');
223 223
 
224 224
             Loader::lang('file_upload');
225
-            $obj =& get_instance();
225
+            $obj = & get_instance();
226 226
 
227 227
             $this->error_messages = array(
228 228
                 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'),
@@ -239,15 +239,15 @@  discard block
 block discarded – undo
239 239
             );
240 240
 
241 241
             $this->file = array(
242
-                'status'                =>    false,    // True: success upload
243
-                'mime'                  =>    '',       // Empty string
244
-                'filename'              =>    '',       // Empty string
245
-                'original'              =>    '',       // Empty string
246
-                'size'                  =>    0,        // 0 Bytes
247
-                'sizeFormated'          =>    '0B',     // 0 Bytes
248
-                'destination'           =>    './',     // Default: ./
249
-                'allowed_mime_types'    =>    array(),  // Allowed mime types
250
-                'error'                 =>    null,        // File error
242
+                'status'                =>    false, // True: success upload
243
+                'mime'                  =>    '', // Empty string
244
+                'filename'              =>    '', // Empty string
245
+                'original'              =>    '', // Empty string
246
+                'size'                  =>    0, // 0 Bytes
247
+                'sizeFormated'          =>    '0B', // 0 Bytes
248
+                'destination'           =>    './', // Default: ./
249
+                'allowed_mime_types'    =>    array(), // Allowed mime types
250
+                'error'                 =>    null, // File error
251 251
             );
252 252
 
253 253
             // Change dir to current dir
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
             } elseif (isset($HTTP_POST_FILES) && is_array($HTTP_POST_FILES)) {
260 260
                 $this->file_array = $HTTP_POST_FILES;
261 261
             }
262
-            $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
262
+            $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array));
263 263
         }
264 264
         /**
265 265
         *    Set input.
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         */
276 276
         public function setInput($input)
277 277
         {
278
-            if (!empty($input) && (is_string($input) || is_numeric($input) )) {
278
+            if (!empty($input) && (is_string($input) || is_numeric($input))) {
279 279
                 $this->input = $input;
280 280
             }
281 281
             return $this;
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
         */
312 312
         public function setAutoFilename()
313 313
         {
314
-            $this->filename = sha1(mt_rand(1, 9999).uniqid());
314
+            $this->filename = sha1(mt_rand(1, 9999) . uniqid());
315 315
             $this->filename .= time();
316 316
             return $this;
317 317
         }
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
                 $php_size = $this->sizeInBytes(ini_get('upload_max_filesize'));
333 333
                 // Calculate difference
334 334
                 if ($php_size < $file_size) {
335
-                    $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']');
335
+                    $this->logger->warning('The upload max file size you set [' . $file_size . '] is greather than the PHP configuration for upload max file size [' . $php_size . ']');
336 336
                 }
337 337
                 $this->max_file_size = $file_size;
338 338
             }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
         public function setAllowedMimeTypes(array $mimes)
351 351
         {
352 352
             if (count($mimes) > 0) {
353
-                array_map(array($this , 'setAllowMimeType'), $mimes);
353
+                array_map(array($this, 'setAllowMimeType'), $mimes);
354 354
             }
355 355
             return $this;
356 356
         }
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
         {
416 416
             if (!empty($name) && is_string($name)) {
417 417
                 if (array_key_exists($name, $this->mime_helping)) {
418
-                    return $this->setAllowedMimeTypes($this->mime_helping[ $name ]);
418
+                    return $this->setAllowedMimeTypes($this->mime_helping[$name]);
419 419
                 }
420 420
             }
421 421
             return $this;
@@ -434,8 +434,8 @@  discard block
 block discarded – undo
434 434
         */
435 435
         public function setUploadFunction($function)
436 436
         {
437
-            if (!empty($function) && (is_array($function) || is_string($function) )) {
438
-                if (is_callable( $function)) {
437
+            if (!empty($function) && (is_array($function) || is_string($function))) {
438
+                if (is_callable($function)) {
439 439
                     $this->upload_function = $function;
440 440
                 }
441 441
             }
@@ -488,8 +488,8 @@  discard block
 block discarded – undo
488 488
                             chdir($destination_directory);
489 489
                         }
490 490
                     }
491
-                    else{
492
-                        $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
491
+                    else {
492
+                        $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']');
493 493
                     }
494 494
                 }
495 495
             }
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
         public function isFilename($filename)
540 540
         {
541 541
             $filename = basename($filename);
542
-            return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
542
+            return (!empty($filename) && (is_string($filename) || is_numeric($filename)));
543 543
         }
544 544
         /**
545 545
         *    Validate mime type with allowed mime types,
@@ -581,11 +581,11 @@  discard block
 block discarded – undo
581 581
         */
582 582
         public function isDirpath($path)
583 583
         {
584
-            if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
584
+            if (!empty($path) && (is_string($path) || is_numeric($path))) {
585 585
                 if (DIRECTORY_SEPARATOR == '/') {
586
-                    return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 );
586
+                    return (preg_match('/^[^*?"<>|:]*$/', $path) == 1);
587 587
                 } else {
588
-                    return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1);
588
+                    return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1);
589 589
                 }
590 590
             }
591 591
             return false;
@@ -613,10 +613,10 @@  discard block
 block discarded – undo
613 613
         */
614 614
         public function getInfo()
615 615
         {
616
-            return (object)$this->file;
616
+            return (object) $this->file;
617 617
         }
618 618
 
619
-        public function isUploaded(){
619
+        public function isUploaded() {
620 620
             return isset($this->file_array[$this->input])
621 621
             &&
622 622
             is_uploaded_file($this->file_array[$this->input]['tmp_name']);
@@ -629,9 +629,9 @@  discard block
 block discarded – undo
629 629
         *    @return    boolean
630 630
         *    @method    boolean    save
631 631
         */
632
-        public function save(){
632
+        public function save() {
633 633
             //check if file upload is  allowed in the configuration
634
-            if(! ini_get('file_uploads')){
634
+            if (!ini_get('file_uploads')) {
635 635
                 $this->setError($this->error_messages['file_uploads']);
636 636
                 return false;
637 637
             }
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
                     if (empty($this->filename)) {
642 642
                         $this->filename = $this->file_array[$this->input]['name'];
643 643
                     }
644
-                    else{
644
+                    else {
645 645
                         // Replace %s for extension in filename
646 646
                         // Before: /[\w\d]*(.[\d\w]+)$/i
647 647
                         // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
                             '$1',
653 653
                             $this->file_array[$this->input]['name']
654 654
                         );
655
-                        $this->filename = $this->filename.'.'.$extension;
655
+                        $this->filename = $this->filename . '.' . $extension;
656 656
                     }
657 657
 
658 658
                     // set file info
@@ -665,10 +665,10 @@  discard block
 block discarded – undo
665 665
                     $this->file['filename']     = $this->filename;
666 666
                     $this->file['error']        = $this->file_array[$this->input]['error'];
667 667
 
668
-                    $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file));
668
+                    $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file));
669 669
 
670 670
                     //check for php upload error
671
-                    if(is_numeric($this->file['error']) && $this->file['error'] > 0){
671
+                    if (is_numeric($this->file['error']) && $this->file['error'] > 0) {
672 672
                         $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
673 673
                         return false;
674 674
                     }
@@ -697,8 +697,8 @@  discard block
 block discarded – undo
697 697
                     }
698 698
 
699 699
                     // Execute input callback
700
-                    if (!empty( $this->callbacks['input'])) {
701
-                        call_user_func($this->callbacks['input'], (object)$this->file);
700
+                    if (!empty($this->callbacks['input'])) {
701
+                        call_user_func($this->callbacks['input'], (object) $this->file);
702 702
                     }
703 703
                    
704 704
 
@@ -710,8 +710,8 @@  discard block
 block discarded – undo
710 710
                     );
711 711
 
712 712
                     // Execute output callback
713
-                    if (!empty( $this->callbacks['output'])) {
714
-                        call_user_func($this->callbacks['output'], (object)$this->file);
713
+                    if (!empty($this->callbacks['output'])) {
714
+                        call_user_func($this->callbacks['output'], (object) $this->file);
715 715
                     }
716 716
                     return $this->file['status'];
717 717
                 }
@@ -730,10 +730,10 @@  discard block
 block discarded – undo
730 730
         */
731 731
         public function sizeFormat($size, $precision = 2)
732 732
         {
733
-            if($size > 0){
733
+            if ($size > 0) {
734 734
                 $base       = log($size) / log(1024);
735 735
                 $suffixes   = array('B', 'K', 'M', 'G', 'T');
736
-                return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
736
+                return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
737 737
             }
738 738
             return null;
739 739
         }
@@ -757,14 +757,14 @@  discard block
 block discarded – undo
757 757
             if (array_key_exists('unit', $matches)) {
758 758
                 $unit = strtoupper($matches['unit']);
759 759
             }
760
-            return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ;
760
+            return (floatval($matches['size']) * pow(1024, $units[$unit]));
761 761
         }
762 762
 
763 763
         /**
764 764
          * Get the upload error message
765 765
          * @return string
766 766
          */
767
-        public function getError(){
767
+        public function getError() {
768 768
             return $this->error;
769 769
         }
770 770
 
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
          * Set the upload error message
773 773
          * @param string $message the upload error message to set
774 774
          */
775
-        public function setError($message){
775
+        public function setError($message) {
776 776
             $this->logger->info('The upload got error : ' . $message);
777 777
             $this->error = $message;
778 778
         }
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
          * @param  int $code the error code
783 783
          * @return string the error message
784 784
          */
785
-        private function getPhpUploadErrorMessageByCode($code){
785
+        private function getPhpUploadErrorMessageByCode($code) {
786 786
             $codeMessageMaps = array(
787 787
                 1 => $this->error_messages['upload_err_ini_size'],
788 788
                 2 => $this->error_messages['upload_err_form_size'],
Please login to merge, or discard this patch.
tests/tnhfw/classes/DBSessionHandlerTest.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 
48 48
 		
49 49
 		
50
-		public function testUsingSessionConfiguration(){
50
+		public function testUsingSessionConfiguration() {
51 51
 			//using value in the configuration
52 52
 			static::$config->set('session_save_path', 'DBSessionModel');
53 53
 			static::$config->set('session_secret', $this->secret);
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
74 74
 		}
75 75
 		
76
-		public function testWhenDataIsExpired(){
76
+		public function testWhenDataIsExpired() {
77 77
 			$dbsh = new DBSessionHandler($this->model);
78 78
 			$dbsh->setSessionSecret($this->secret);
79 79
 			
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 			$this->assertFalse($dbsh->read('foo'));
87 87
 		}
88 88
 		
89
-		public function testWhenDataAlreadyExistDoUpdate(){
89
+		public function testWhenDataAlreadyExistDoUpdate() {
90 90
 			$dbsh = new DBSessionHandler($this->model);
91 91
 			$dbsh->setSessionSecret($this->secret);
92 92
 			
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 			$this->assertEquals($dbsh->read('foo'), '445');	
100 100
 		}
101 101
 		
102
-		public function testUsingCustomModelInstance(){
102
+		public function testUsingCustomModelInstance() {
103 103
 			$dbsh = new DBSessionHandler($this->model);
104 104
 			$dbsh->setSessionSecret($this->secret);
105 105
 			
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		}
128 128
 			
129 129
 			
130
-		public function testUsingCustomLogInstance(){
130
+		public function testUsingCustomLogInstance() {
131 131
 			$dbsh = new DBSessionHandler($this->model, new Log());
132 132
 			$dbsh->setSessionSecret($this->secret);
133 133
 			
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
155 155
 		}
156 156
 		
157
-		public function testUsingCustomLoaderInstance(){
157
+		public function testUsingCustomLoaderInstance() {
158 158
 			$dbsh = new DBSessionHandler($this->model, null, new Loader());
159 159
 			$dbsh->setSessionSecret($this->secret);
160 160
 			
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 		}
183 183
 		
184 184
 		
185
-		public function testWhenModelInsanceIsNotSet(){
185
+		public function testWhenModelInsanceIsNotSet() {
186 186
 			$dbsh = new DBSessionHandler(null, null, new Loader());
187 187
 			$dbsh->setSessionSecret($this->secret);
188 188
 			
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
211 211
 		}
212 212
 		
213
-		public function testWhenModelTableColumnsIsNotSet(){
213
+		public function testWhenModelTableColumnsIsNotSet() {
214 214
 			//session table is empty
215 215
 			$this->model->setSessionTableColumns(array());
216 216
 			$dbsh = new DBSessionHandler($this->model);
Please login to merge, or discard this patch.