Completed
Push — master ( 226d76...161fc8 )
by Song
02:24
created

Downloadable::display()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 28

Duplication

Lines 7
Ratio 25 %

Importance

Changes 0
Metric Value
cc 5
nc 2
nop 1
dl 7
loc 28
rs 9.1608
c 0
b 0
f 0
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 Downloadable extends AbstractDisplayer
9
{
10
    public function display($server = '')
11
    {
12
        if ($this->value instanceof Arrayable) {
13
            $this->value = $this->value->toArray();
14
        }
15
16
        return collect((array) $this->value)->filter()->map(function ($value) use ($server) {
17
            if (empty($value)) {
18
                return '';
19
            }
20
21 View Code Duplication
            if (url()->isValidUrl($value)) {
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...
22
                $src = $value;
23
            } elseif ($server) {
24
                $src = rtrim($server, '/').'/'.ltrim($value, '/');
25
            } else {
26
                $src = Storage::disk(config('admin.upload.disk'))->url($value);
27
            }
28
29
            $name = basename($value);
30
31
            return <<<HTML
32
<a href='$src' download='{$name}' target='_blank' class='text-muted'>
33
    <i class="fa fa-download"></i> {$name}
34
</a>
35
HTML;
36
        })->implode('<br>');
37
    }
38
}
39