LogoLink::collectData()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
ccs 0
cts 17
cp 0
cc 3
nc 4
nop 0
crap 12
1
<?php
2
/**
3
 * Pluggable themes for Yii2
4
 *
5
 * @link      https://github.com/hiqdev/yii2-thememanager
6
 * @package   yii2-thememanager
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\thememanager\widgets;
12
13
use Yii;
14
use yii\base\Widget;
15
16
/**
17
 * LogoLink widget.
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class LogoLink extends Widget
21
{
22
    /**
23
     * @var array html options
24
     */
25
    public $options = [];
26
27
    /**
28
     * @var string url to image
29
     */
30
    public $image;
31
32
    /**
33
     * @var string text to display
34
     */
35
    public $name;
36
37
    /**
38
     * @var array|string text to display
39
     */
40
    public $url;
41
42
    public $smallImage;
43
44
    public $imageOptions = [];
45
46
    public $smallImageOptions = [];
47
48
    public function run()
49
    {
50
        return $this->render('LogoLink', $this->collectData());
51
    }
52
53
    protected function collectData()
54
    {
55
        $data = [
56
            'name' => $this->name,
57
            'url' => $this->url,
58
            'options' => $this->options,
59
        ];
60
        if ($this->smallImage) {
61
            $data['smallImage'] = $this->getImage($this->smallImage);
62
            $data['smallImageOptions'] = $this->smallImageOptions;
63
        }
64
        if ($this->image) {
65
            $data['image'] = $this->getImage($this->image);
66
            $data['imageOptions'] = $this->imageOptions;
67
        }
68
69
        return $data;
70
    }
71
72
    protected function getImage($path)
73
    {
74
        return mb_substr($path, 0, 1, 'utf-8') === '@' ? Yii::$app->assetManager->publish($path)[1] : $path;
75
    }
76
}
77