Completed
Push — master ( 1408f3...b929a0 )
by wen
14:35
created

Image::getValue()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 3
nop 0
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
    protected $disk;
16
17
    /**
18
     * @return string
19
     */
20
    public function getImageWidth()
21
    {
22
        return $this->imageWidth;
23
    }
24
25
    /**
26
     * @param string $width
27
     *
28
     * @return $this
29
     */
30
    public function setImageWidth($width)
31
    {
32
        $this->imageWidth = $width;
33
34
        return $this;
35
    }
36
37
    public function getDisk()
38
    {
39
        if ($this->disk) {
40
            return $this->disk;
41
        }
42
    }
43
44
    public function setDisk($value)
45
    {
46
        $this->disk = $value;
47
48
        return $this;
49
    }
50
51
    public function getValue()
52
    {
53
        $value = parent::getValue();
54
        if (!empty($value) && (strpos($value, '://') === false)) {
55
            if (($disk = $this->getDisk())) {
56
                $value = \Storage::disk($disk)->url($value);
57
            } else {
58
                $value = asset($value);
59
            }
60
        }
61
62
        return [
63
            'image' => $value,
64
            'width' => $this->getImageWidth(),
65
        ];
66
    }
67
}
68