Completed
Push — master ( 815d92...46416a )
by Song
02:21
created

Image   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A display() 0 18 4
1
<?php
2
3
namespace Encore\Admin\Grid\Displayers;
4
5
use Illuminate\Contracts\Support\Arrayable;
6
use Illuminate\Support\Facades\Storage;
7
8
class Image extends AbstractDisplayer
9
{
10
    public function display($server = '', $width = 200, $height = 200)
11
    {
12
        if ($this->value instanceof Arrayable) {
13
            $this->value = $this->value->toArray();
14
        }
15
16
        return collect((array) $this->value)->filter()->map(function ($path) use ($server, $width, $height) {
17
            if (url()->isValidUrl($path)) {
18
                $src = $path;
19
            } elseif ($server) {
20
                $src = rtrim($server, '/').'/'.ltrim($path, '/');
21
            } else {
22
                $src = Storage::disk(config('admin.upload.disk'))->url($path);
23
            }
24
25
            return "<img src='$src' style='max-width:{$width}px;max-height:{$height}px' class='img img-thumbnail' />";
26
        })->implode('&nbsp;');
27
    }
28
}
29