Test Failed
Branch master (e86ba3)
by Sergio
16:12 queued 13:45
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
         ];
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
      */
234 234
     public function loadFile()
235 235
     {
236
-        if($this->isFile()){
237
-            $this->owner->file = $this->getFileInstance();//virtual attribute
236
+        if ($this->isFile()) {
237
+            $this->owner->file = $this->getFileInstance(); //virtual attribute
238 238
             $this->owner->{$this->nameOfAttributeStorage} = $this->getNewFileName();
239 239
         }
240 240
     }
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
      */
268 268
     public function afterDelete($event)
269 269
     {
270
-        if($this->deleteImageWithRecord){
271
-            foreach($this->targets as $target){
270
+        if ($this->deleteImageWithRecord) {
271
+            foreach ($this->targets as $target) {
272 272
                 $dirPath = $this->getPath($target['path']);
273 273
                 FileHelper::removeDirectory($dirPath);
274 274
             }    
@@ -287,16 +287,16 @@  discard block
 block discarded – undo
287 287
     {
288 288
         if ($this->isFile() && $this->inScenario())
289 289
         {
290
-            foreach($this->targets as $target){
290
+            foreach ($this->targets as $target) {
291 291
                 $dirPath = $this->getPath($target['path']);
292 292
                 
293
-                if(!$insert){
293
+                if (!$insert) {
294 294
                     
295 295
                     FileHelper::removeDirectory($dirPath);
296 296
                 }
297 297
                 
298 298
                 FileHelper::createDirectory($dirPath);
299
-                $newFilePath = $dirPath . $this->getNewFileName();
299
+                $newFilePath = $dirPath.$this->getNewFileName();
300 300
 
301 301
                 $this->getHendler($target['hendler'], $this->getFileInstance()->tempName, $newFilePath);
302 302
                 
@@ -309,29 +309,29 @@  discard block
 block discarded – undo
309 309
      * @param string $path
310 310
      * @return string $dirPath
311 311
      */
312
-    protected function getPath($path){
313
-        if(is_string($path)){
314
-            $path = rtrim($path, '/') . '/';
312
+    protected function getPath($path) {
313
+        if (is_string($path)) {
314
+            $path = rtrim($path, '/').'/';
315 315
             $dirPath = \Yii::getAlias($path);
316 316
         }
317 317
         elseif ($path instanceof Closure || (is_array($path) && is_callable($path))) {
318 318
             $dirPath = $path($this->owner->attributes);
319
-        }else{
319
+        } else {
320 320
             throw new InvalidCallException('Param `path` mast be string instanceof Closure or callable method.');
321 321
         }
322 322
 
323 323
         return $dirPath;
324 324
     }
325 325
 
326
-    protected function getHendler($hendler, $tmp, $path){
326
+    protected function getHendler($hendler, $tmp, $path) {
327 327
         if ($hendler instanceof Closure || (is_array($hendler) && is_callable($hendler))) {
328 328
             $hendler($tmp, $path);
329
-        }elseif(is_array($hendler) && array_key_exists('type', $hendler) && array_key_exists('config', $hendler)){
330
-            if(!in_array($hendler['type'], self::supportedFileTypes()))
329
+        }elseif (is_array($hendler) && array_key_exists('type', $hendler) && array_key_exists('config', $hendler)) {
330
+            if (!in_array($hendler['type'], self::supportedFileTypes()))
331 331
             {
332
-                throw new InvalidConfigException('File type not supported: ' . $hendler['type']);
332
+                throw new InvalidConfigException('File type not supported: '.$hendler['type']);
333 333
             }
334
-            switch($hendler['type']) {
334
+            switch ($hendler['type']) {
335 335
                 case self::TYPE_IMAGE:
336 336
                     $sizeW = $hendler['config']['size']['width'];
337 337
                     $sizeH = $hendler['config']['size']['height'];
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
                 break;
343 343
             }
344 344
 
345
-        }else{
345
+        } else {
346 346
             throw new InvalidCallException('Param `hendler` mast be instanceof Closure ,callable method or array with allowed configs.');
347 347
         }
348 348
 
@@ -383,8 +383,7 @@  discard block
 block discarded – undo
383 383
         $ext = $file->extension;
384 384
         
385 385
          return $this->newFileName ?
386
-            $this->newFileName . '.' . $file->extension :
387
-            $file->baseName . '_' . $this->time . '.' . $file->extension;
386
+            $this->newFileName.'.'.$file->extension : $file->baseName.'_'.$this->time.'.'.$file->extension;
388 387
     }
389 388
 
390 389
     /**
Please login to merge, or discard this patch.