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

Downloadable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 22.58 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A display() 7 28 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 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