Test Failed
Push — master ( 131bb7...5af539 )
by Sergio
14:29
created
src/UploadFileBehavior.php 3 patches
Indentation   +6 added lines, -8 removed lines patch added patch discarded remove patch
@@ -52,8 +52,6 @@  discard block
 block discarded – undo
52 52
  *                    'uploadFileBehavior' => [
53 53
  *                        'class' => UploadFileBehavior::className(),
54 54
  *                        'nameOfAttributeStorage' => 'img_src',
55
-                    
56
-                    
57 55
  *                        'targets' => [
58 56
  *                            
59 57
  *                            [
@@ -173,8 +171,8 @@  discard block
 block discarded – undo
173 171
     private $time = false;
174 172
 
175 173
         /**
176
-     * @inheritdoc
177
-     */
174
+         * @inheritdoc
175
+         */
178 176
     public function init()
179 177
     {
180 178
         parent::init();
@@ -206,9 +204,9 @@  discard block
 block discarded – undo
206 204
         
207 205
     }
208 206
 
209
-     /**
210
-     * {@inheritdoc}
211
-     */
207
+        /**
208
+         * {@inheritdoc}
209
+         */
212 210
     public function events()
213 211
     {
214 212
         return [
@@ -381,7 +379,7 @@  discard block
 block discarded – undo
381 379
         $baseName = $file->baseName;
382 380
         $ext = $file->extension;
383 381
         
384
-         return $this->newFileName ?
382
+            return $this->newFileName ?
385 383
             $this->newFileName . '.' . $file->extension :
386 384
             $file->baseName . '_' . $this->time . '.' . $file->extension;
387 385
     }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -21 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 class UploadFileBehavior extends Behavior
106 106
 {
107 107
     const TYPE_IMAGE = 'image';
108
-    const TYPE_FILE = 'file';//not supported yet
108
+    const TYPE_FILE = 'file'; //not supported yet
109 109
     
110 110
     /**
111 111
      * Name of attribute for recording file from form to ActiveRecord. DEfault name of attribute is `file`
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
         ];
221 221
     }
222 222
 
223
-    protected static function supportedFileTypes(){
223
+    protected static function supportedFileTypes() {
224 224
         return [
225 225
             self::TYPE_IMAGE
226 226
         ];
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
      */
235 235
     public function loadFile()
236 236
     {
237
-        if($this->isFile()){
238
-            $this->owner->file = $this->getFileInstance();//virtual attribute
237
+        if ($this->isFile()) {
238
+            $this->owner->file = $this->getFileInstance(); //virtual attribute
239 239
             $this->owner->{$this->nameOfAttributeStorage} = $this->getNewFileName();
240 240
         }
241 241
     }
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
      */
271 271
     public function afterDelete($event)
272 272
     {
273
-        if($this->deleteImageWithRecord){
274
-            foreach($this->targets as $target){
273
+        if ($this->deleteImageWithRecord) {
274
+            foreach ($this->targets as $target) {
275 275
                 $dirPath = $this->getPath($target['path']);
276 276
                 FileHelper::removeDirectory($dirPath);
277 277
             }    
@@ -290,16 +290,16 @@  discard block
 block discarded – undo
290 290
     {
291 291
         if ($this->isFile() && $this->inScenario())
292 292
         {
293
-            foreach($this->targets as $target){
293
+            foreach ($this->targets as $target) {
294 294
                 $dirPath = $this->getPath($target['path']);
295 295
                 
296
-                if(!$insert){
296
+                if (!$insert) {
297 297
                     
298 298
                     FileHelper::removeDirectory($dirPath);
299 299
                 }
300 300
                 
301 301
                 FileHelper::createDirectory($dirPath);
302
-                $newFilePath = $dirPath . $this->getNewFileName();
302
+                $newFilePath = $dirPath.$this->getNewFileName();
303 303
 
304 304
                 $this->getHendler($target['hendler'], $this->getFileInstance()->tempName, $newFilePath);
305 305
                 
@@ -308,29 +308,29 @@  discard block
 block discarded – undo
308 308
         return false;
309 309
     }
310 310
 
311
-    protected function getPath($path){
312
-        if(is_string($path)){
313
-            $path = rtrim($path, '/') . '/';
311
+    protected function getPath($path) {
312
+        if (is_string($path)) {
313
+            $path = rtrim($path, '/').'/';
314 314
             $dirPath = \Yii::getAlias($path);
315 315
         }
316 316
         elseif ($path instanceof Closure || (is_array($path) && is_callable($path))) {
317 317
             $dirPath = $path($this->owner->attributes);
318
-        }else{
318
+        } else {
319 319
             throw new InvalidCallException('Param `path` mast be string instanceof Closure or callable method.');
320 320
         }
321 321
 
322 322
         return $dirPath;
323 323
     }
324 324
 
325
-    protected function getHendler($hendler, $tmp, $path){
325
+    protected function getHendler($hendler, $tmp, $path) {
326 326
         if ($hendler instanceof Closure || (is_array($hendler) && is_callable($hendler))) {
327 327
             $hendler($tmp, $path);
328
-        }elseif(is_array($hendler) && array_key_exists('type', $hendler) && array_key_exists('config', $hendler)){
329
-            if(!in_array($hendler['type'], self::supportedFileTypes()))
328
+        }elseif (is_array($hendler) && array_key_exists('type', $hendler) && array_key_exists('config', $hendler)) {
329
+            if (!in_array($hendler['type'], self::supportedFileTypes()))
330 330
             {
331
-                throw new InvalidConfigException('File type not supported: ' . $hendler['type']);
331
+                throw new InvalidConfigException('File type not supported: '.$hendler['type']);
332 332
             }
333
-            switch($hendler['type']) {
333
+            switch ($hendler['type']) {
334 334
                 case self::TYPE_IMAGE:
335 335
                     $sizeW = $hendler['config']['size']['width'];
336 336
                     $sizeH = $hendler['config']['size']['height'];
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
                 break;
342 342
             }
343 343
 
344
-        }else{
344
+        } else {
345 345
             throw new InvalidCallException('Param `hendler` mast be instanceof Closure ,callable method or array with allowed configs.');
346 346
         }
347 347
 
@@ -382,8 +382,7 @@  discard block
 block discarded – undo
382 382
         $ext = $file->extension;
383 383
         
384 384
          return $this->newFileName ?
385
-            $this->newFileName . '.' . $file->extension :
386
-            $file->baseName . '_' . $this->time . '.' . $file->extension;
385
+            $this->newFileName.'.'.$file->extension : $file->baseName.'_'.$this->time.'.'.$file->extension;
387 386
     }
388 387
 
389 388
     /**
Please login to merge, or discard this patch.
Braces   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -312,10 +312,9 @@  discard block
 block discarded – undo
312 312
         if(is_string($path)){
313 313
             $path = rtrim($path, '/') . '/';
314 314
             $dirPath = \Yii::getAlias($path);
315
-        }
316
-        elseif ($path instanceof Closure || (is_array($path) && is_callable($path))) {
315
+        } elseif ($path instanceof Closure || (is_array($path) && is_callable($path))) {
317 316
             $dirPath = $path($this->owner->attributes);
318
-        }else{
317
+        } else{
319 318
             throw new InvalidCallException('Param `path` mast be string instanceof Closure or callable method.');
320 319
         }
321 320
 
@@ -325,7 +324,7 @@  discard block
 block discarded – undo
325 324
     protected function getHendler($hendler, $tmp, $path){
326 325
         if ($hendler instanceof Closure || (is_array($hendler) && is_callable($hendler))) {
327 326
             $hendler($tmp, $path);
328
-        }elseif(is_array($hendler) && array_key_exists('type', $hendler) && array_key_exists('config', $hendler)){
327
+        } elseif(is_array($hendler) && array_key_exists('type', $hendler) && array_key_exists('config', $hendler)){
329 328
             if(!in_array($hendler['type'], self::supportedFileTypes()))
330 329
             {
331 330
                 throw new InvalidConfigException('File type not supported: ' . $hendler['type']);
@@ -341,7 +340,7 @@  discard block
 block discarded – undo
341 340
                 break;
342 341
             }
343 342
 
344
-        }else{
343
+        } else{
345 344
             throw new InvalidCallException('Param `hendler` mast be instanceof Closure ,callable method or array with allowed configs.');
346 345
         }
347 346
 
Please login to merge, or discard this patch.