Completed
Push — master ( 76f5f2...34a032 )
by Klochok
02:47
created

LogoLink::getImage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 2
eloc 2
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * Theme Manager 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
 */
19
class LogoLink extends Widget
20
{
21
    /**
22
     * @var array html options
23
     */
24
    public $options = [];
25
26
    /**
27
     * @var string url to image
28
     */
29
    public $image;
30
31
    /**
32
     * @var string text to display
33
     */
34
    public $name;
35
36
    /**
37
     * @var array|string text to display
38
     */
39
    public $url;
40
41
    public $smallImage;
42
43
    public $imageOptions = [];
44
45
    public $smallImageOptions = [];
46
47
    public function run()
48
    {
49
        return $this->render('LogoLink', $this->collectData());
50
    }
51
52
    protected function collectData()
53
    {
54
        $data = [
55
            'name' => $this->name,
56
            'url' => $this->url,
57
            'options' => $this->options,
58
        ];
59
        if ($this->smallImage) {
60
            $data['smallImage'] = $this->getImage($this->smallImage);
61
            $data['smallImageOptions'] = $this->smallImageOptions;
62
        }
63
        if ($this->image) {
64
            $data['image'] = $this->getImage($this->image);
65
            $data['imageOptions'] = $this->imageOptions;
66
        }
67
68
        return $data;
69
    }
70
71
    protected function getImage($path)
72
    {
73
        return mb_substr($path, 0, 1, 'utf-8') === '@' ? Yii::$app->assetManager->publish($path)[1] : $path;
74
    }
75
}
76