Completed
Push — master ( d357e4...815d92 )
by Song
02:27
created

Image   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 22
Duplicated Lines 31.82 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B display() 7 19 7

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
use Encore\Admin\Admin;
8
9
class Image extends AbstractDisplayer
10
{
11
    public function display($server = '', $width = 200, $height = 200, $expand = false)
12
    {
13
        if ($this->value instanceof Arrayable) {
14
            $this->value = $this->value->toArray();
15
        }
16
17
        return collect((array) $this->value)->filter()->map(function ($path) use ($server, $width, $height, $expand) {
18 View Code Duplication
            if (url()->isValidUrl($path)) {
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...
19
                $src = $path;
20
            } elseif ($server) {
21
                $src = $server.$path;
22
            } else {
23
                $src = Storage::disk(config('admin.upload.disk'))->url($path);
24
            }
25
26
            if ($expand) Admin::script("$('img.img-expand').on('click', function() { $('.img-expanded').attr('src', $(this).attr('src')); $('#img-expand-" . $this->getKey() . "').modal('show'); });");
27
            return ($expand?'<div class="modal fade" id="img-expand-' . $this->getKey() . '" tabindex="-1" role="dialog" aria-labelledby="img-expand" aria-hidden="true"><div class="modal-dialog modal-lg" role="document"><div class="modal-content"><div class="modal-body"><img src="" class="img-expanded" style="width: 100%;"></div></div></div></div>':'') . "<img src='$src' style='max-width:{$width}px;max-height:{$height}px' class='img img-thumbnail" . ($expand?' img-expand':'') . "' />";
28
        })->implode('&nbsp;');
29
    }
30
}
31