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