Total Complexity | 7 |
Total Lines | 67 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class ImageColumn implements ColumnFormatter { |
||
13 | |||
14 | /** @var string */ |
||
15 | private $_classes; |
||
16 | |||
17 | /** @var string */ |
||
18 | private $_fallback; |
||
19 | |||
20 | /** |
||
21 | * ImageColumn constructor. |
||
22 | * @param null|string $fallback |
||
23 | * @param null|string $classes |
||
24 | */ |
||
25 | 4 | public function __construct(? string $fallback = null, ? string $classes = null) |
|
26 | { |
||
27 | 4 | $this->_fallback = $fallback; |
|
28 | 4 | $this->_classes = $classes; |
|
29 | 4 | } |
|
30 | |||
31 | /** |
||
32 | * @param Model $rowModel |
||
33 | * @param string $column |
||
34 | * @return string |
||
35 | */ |
||
36 | 4 | public function format(Model $rowModel, string $column) : string |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param string $path |
||
48 | * @return string |
||
49 | */ |
||
50 | 2 | private function _renderImage(string $path) : string |
|
51 | { |
||
52 | 2 | return '<img src="' . $path . (!empty($this->_classes) ? ('" class="' . $this->_classes) : '') . '"/>'; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Add styling to the image. |
||
57 | * |
||
58 | * @param string $classes |
||
59 | * @return ImageColumn |
||
60 | */ |
||
61 | 1 | public function classes(string $classes) : ImageColumn |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Set a fallback value which is used when the image is not found. |
||
70 | * |
||
71 | * @param string $fallback |
||
72 | * @return ImageColumn |
||
73 | */ |
||
74 | 1 | public function fallback(string $fallback) : ImageColumn |
|
79 | } |
||
80 | } |