Completed
Push — master ( 48ff0c...a157cb )
by wen
03:02
created

Image   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 62
c 1
b 0
f 1
wmc 9
lcom 1
cbo 2
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getImageWidth() 0 4 1
A setImageWidth() 0 6 1
A getDisk() 0 6 2
A setDisk() 0 6 1
A getModelValue() 0 16 4
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 getModelValue()
52
    {
53
        $value = parent::getModelValue();
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