Completed
Push — master ( 3a6a8b...8c64c3 )
by Song
02:41
created

Download   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 21.88 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A display() 7 29 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Download 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
18
            if (empty($value)) {
19
                return '';
20
            }
21
22 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...
23
                $src = $value;
24
            } elseif ($server) {
25
                $src = rtrim($server, '/').'/'.ltrim($value, '/');
26
            } else {
27
                $src = Storage::disk(config('admin.upload.disk'))->url($value);
28
            }
29
30
            $name = basename($value);
31
32
            return <<<HTML
33
<a href='$src' download='{$name}' target='_blank' class='text-muted'>
34
    <i class="fa fa-download"></i> {$name}
35
</a>
36
HTML;
37
        })->implode('<br>');
38
    }
39
}
40