GetFileUrlTrait::getFileUrl()   B
last analyzed

Complexity

Conditions 6
Paths 7

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 8.9617
c 0
b 0
f 0
cc 6
nc 7
nop 1
1
<?php
2
3
namespace maxmirazh33\file;
4
5
/**
6
 * @property \yii\base\Behavior[] $behaviors
7
 */
8
trait GetFileUrlTrait
9
{
10
    /**
11
     * @param string $attr name of attribute
12
     * @return null|string url to file
13
     * @throws \ReflectionException
14
     */
15
    public function getFileUrl($attr)
16
    {
17
        foreach ($this->behaviors as $behavior) {
18
            if ($behavior instanceof Behavior) {
19
                return $behavior->getFileUrl($attr);
20
            }
21
        }
22
23
        $class = new \ReflectionClass($this);
24
        $class = 'backend\models\\' . $class->getShortName();
25
        if (class_exists($class)) {
26
            $model = new $class;
27
            foreach ($model->behaviors as $behavior) {
28
                if ($behavior instanceof Behavior) {
29
                    return $behavior->getFileUrl($attr, $this);
30
                }
31
            }
32
        }
33
34
        return null;
35
    }
36
}
37