Test Failed
Push — master ( 131bb7...5af539 )
by Sergio
14:29
created
src/UploadFileBehavior.php 1 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.