GetImageUrlTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getImageUrl() 0 21 6
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