Completed
Push — master ( 64fc42...5cbacf )
by Song
02:43
created

Carousel::display()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 30

Duplication

Lines 7
Ratio 23.33 %

Importance

Changes 0
Metric Value
cc 6
nc 4
nop 3
dl 7
loc 30
rs 8.8177
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Grid\Displayers;
4
5
use Encore\Admin\Widgets\Carousel as CarouselWidget;
6
use Illuminate\Contracts\Support\Arrayable;
7
use Illuminate\Support\Facades\Storage;
8
9
class Carousel extends AbstractDisplayer
10
{
11
    public function display(int $width = 300, int $height = 200, $server = '')
12
    {
13
        if ($this->value instanceof Arrayable) {
14
            $this->value = $this->value->toArray();
15
        }
16
17
        $this->value = array_values($this->value);
18
19
        if (empty($this->value)) {
20
            return '';
21
        }
22
23
        $images = collect((array) $this->value)->filter()->map(function ($path) use ($server) {
24 View Code Duplication
            if (url()->isValidUrl($path) || strpos($path, 'data:image') === 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
                $image = $path;
26
            } elseif ($server) {
27
                $image = rtrim($server, '/').'/'.ltrim($path, '/');
28
            } else {
29
                $image = Storage::disk(config('admin.upload.disk'))->url($path);
30
            }
31
32
            $caption = '';
33
34
            return compact('image', 'caption');
35
        });
36
37
        $id = sprintf('carousel-%s-%s', $this->column->getName(), $this->getKey());
38
39
        return (new CarouselWidget($images))->width($width)->height($height)->id($id);
40
    }
41
}