Completed
Push — develop ( 29208e...50a0ec )
by Adrien
05:34
created

Drawing   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 125
Duplicated Lines 24 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 38.89%

Importance

Changes 0
Metric Value
dl 30
loc 125
rs 10
c 0
b 0
f 0
ccs 14
cts 36
cp 0.3889
wmc 14
lcom 1
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getPath() 0 4 1
A __clone() 11 11 3
A getFilename() 0 4 1
A getIndexedFilename() 0 7 1
A getExtension() 0 6 1
B setPath() 19 19 5
A getHashCode() 0 8 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 PhpOffice\PhpSpreadsheet\Worksheet;
4
5
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
6
use PhpOffice\PhpSpreadsheet\IComparable;
7
8
class Drawing extends BaseDrawing implements IComparable
9
{
10
    /**
11
     * Path.
12
     *
13
     * @var string
14
     */
15
    private $path;
16
17
    /**
18
     * Create a new Drawing.
19
     */
20 1
    public function __construct()
21
    {
22
        // Initialise values
23 1
        $this->path = '';
24
25
        // Initialize parent
26 1
        parent::__construct();
27 1
    }
28
29
    /**
30
     * Get Filename.
31
     *
32
     * @return string
33
     */
34
    public function getFilename()
35
    {
36
        return basename($this->path);
37
    }
38
39
    /**
40
     * Get indexed filename (using image index).
41
     *
42
     * @return string
43
     */
44
    public function getIndexedFilename()
45
    {
46
        $fileName = $this->getFilename();
47
        $fileName = str_replace(' ', '_', $fileName);
48
49
        return str_replace('.' . $this->getExtension(), '', $fileName) . $this->getImageIndex() . '.' . $this->getExtension();
50
    }
51
52
    /**
53
     * Get Extension.
54
     *
55
     * @return string
56
     */
57
    public function getExtension()
58
    {
59
        $exploded = explode('.', basename($this->path));
60
61
        return $exploded[count($exploded) - 1];
62
    }
63
64
    /**
65
     * Get Path.
66
     *
67
     * @return string
68
     */
69 1
    public function getPath()
70
    {
71 1
        return $this->path;
72
    }
73
74
    /**
75
     * Set Path.
76
     *
77
     * @param string $pValue File path
78
     * @param bool $pVerifyFile Verify file
79
     *
80
     * @throws PhpSpreadsheetException
81
     *
82
     * @return Drawing
83
     */
84 1 View Code Duplication
    public function setPath($pValue, $pVerifyFile = true)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
85
    {
86 1
        if ($pVerifyFile) {
87 1
            if (file_exists($pValue)) {
88 1
                $this->path = $pValue;
89
90 1
                if ($this->width == 0 && $this->height == 0) {
91
                    // Get width/height
92 1
                    list($this->width, $this->height) = getimagesize($pValue);
93
                }
94
            } else {
95 1
                throw new PhpSpreadsheetException("File $pValue not found!");
96
            }
97
        } else {
98
            $this->path = $pValue;
99
        }
100
101 1
        return $this;
102
    }
103
104
    /**
105
     * Get hash code.
106
     *
107
     * @return string Hash code
108
     */
109
    public function getHashCode()
110
    {
111
        return md5(
112
            $this->path .
113
            parent::getHashCode() .
114
            __CLASS__
115
        );
116
    }
117
118
    /**
119
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
120
     */
121 View Code Duplication
    public function __clone()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
122
    {
123
        $vars = get_object_vars($this);
124
        foreach ($vars as $key => $value) {
125
            if (is_object($value)) {
126
                $this->$key = clone $value;
127
            } else {
128
                $this->$key = $value;
129
            }
130
        }
131
    }
132
}
133