Completed
Push — master ( 764c30...771e80 )
by wen
03:03
created

Image::setImageWidth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
4
namespace Sco\Admin\View\Columns;
5
6
class Image extends Column
7
{
8
    protected $template = '<img v-img :width="value.width" :src="value.image" v-if="value.image">';
9
10
    /**
11
     * @var string
12
     */
13
    protected $imageWidth = '80px';
14
15
    /**
16
     * @return string
17
     */
18
    public function getImageWidth()
19
    {
20
        return $this->imageWidth;
21
    }
22
23
    /**
24
     * @param string $width
25
     *
26
     * @return $this
27
     */
28
    public function setImageWidth($width)
29
    {
30
        $this->imageWidth = $width;
31
32
        return $this;
33
    }
34
35
    public function getModelValue()
36
    {
37
        $value = parent::getModelValue();
38
        if (!empty($value) && (strpos($value, '://') === false)) {
39
            $value = asset($value);
40
        }
41
42
        return [
43
            'image' => $value,
44
            'width' => $this->getImageWidth(),
45
        ];
46
    }
47
}
48