Passed
Push — master ( 360d9f...31271b )
by Alexander
04:18 queued 01:59
created

FileLoaderBehavior::events()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Horat1us\Yii\Behaviors;
4
5
use yii\base\Behavior;
6
use yii\base\Model;
7
use yii\web\UploadedFile;
8
9
class FileLoaderBehavior extends Behavior
10
{
11
    /** @var string */
12
    public $attribute;
13
14
    /** @var bool */
15
    public $multiple = false;
16
17 2
    public function events()
18
    {
19
        return [
20 2
            Model::EVENT_BEFORE_VALIDATE => 'load',
21
        ];
22
    }
23
24 2
    public function load()
25
    {
26 2
        $this->owner->{$this->attribute} = $this->multiple
27 1
            ? UploadedFile::getInstances($this->owner, $this->attribute)
0 ignored issues
show
Compatibility introduced by
$this->owner of type object<yii\base\Component> is not a sub-type of object<yii\base\Model>. It seems like you assume a child class of the class yii\base\Component to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
28 1
            : UploadedFile::getInstance($this->owner, $this->attribute);
0 ignored issues
show
Compatibility introduced by
$this->owner of type object<yii\base\Component> is not a sub-type of object<yii\base\Model>. It seems like you assume a child class of the class yii\base\Component to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
29
    }
30
}