PictureWidget   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 17
c 1
b 0
f 1
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 14 4
1
<?php
2
3
4
namespace floor12\files\components;
5
6
7
use floor12\files\models\File;
8
use floor12\files\models\FileType;
9
use yii\base\Widget;
10
11
class PictureWidget extends Widget
12
{
13
    /** @var File|null */
14
    public $model;
15
    /** @var integer|array */
16
    public $width;
17
    /** @var string */
18
    public $alt;
19
    /** @var string */
20
    public $classPicture;
21
    /** @var string */
22
    public $classImg;
23
    /** @var string */
24
    public $view = 'pictureWidget';
25
26
    /**
27
     * @return string|null
28
     */
29
    public function run(): ?string
30
    {
31
        if (empty($this->model) || !in_array($this->model->type, [FileType::IMAGE, FileType::VIDEO]))
32
            return null;
33
34
        if (is_array($this->width))
35
            $this->view = 'mediaPictureWidget';
36
37
        return $this->render($this->view, [
38
            'model' => $this->model,
39
            'width' => $this->width,
40
            'alt' => $this->alt,
41
            'classPicture' => $this->classPicture,
42
            'classImg' => $this->classImg,
43
        ]);
44
    }
45
}
46