Image   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 5.56 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 2
dl 3
loc 54
ccs 0
cts 29
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getImageWidth() 0 4 1
A setImageWidth() 0 6 1
A getValue() 3 12 3
A toArray() 0 9 1

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 Sco\Admin\Display\Columns;
4
5
use Sco\Admin\Traits\UploadStorageTrait;
6
7
class Image extends Column
8
{
9
    use UploadStorageTrait;
10
11
    protected $type = 'image';
12
13
    /**
14
     * @var string
15
     */
16
    protected $imageWidth = '80px';
17
18
    /**
19
     * @return string
20
     */
21
    public function getImageWidth()
22
    {
23
        return $this->imageWidth;
24
    }
25
26
    /**
27
     * @param string $width
28
     *
29
     * @return $this
30
     */
31
    public function setImageWidth($width)
32
    {
33
        $this->imageWidth = $width;
34
35
        return $this;
36
    }
37
38
    public function getValue()
39
    {
40
        $value = parent::getValue();
41 View Code Duplication
        if (! empty($value) && (strpos($value, '://') === false)) {
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...
42
            $value = $this->getFileUrl($value);
43
        }
44
45
        return [
46
            'image' => $value,
47
            'width' => $this->getImageWidth(),
48
        ];
49
    }
50
51
    public function toArray()
52
    {
53
        return parent::toArray() + [
54
                'options' => [
55
                    'toolbar' => false,
56
                    'navbar'  => false,
57
                ],
58
            ];
59
    }
60
}
61