Total Complexity | 7 |
Total Lines | 72 |
Duplicated Lines | 11.11 % |
Coverage | 70% |
Changes | 0 |
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 |
||
8 | class Run extends TextElement implements ITextElement |
||
9 | { |
||
10 | /** |
||
11 | * Font. |
||
12 | * |
||
13 | * @var Font |
||
14 | */ |
||
15 | private $font; |
||
16 | |||
17 | /** |
||
18 | * Create a new Run instance. |
||
19 | * |
||
20 | * @param string $pText Text |
||
21 | */ |
||
22 | 30 | public function __construct($pText = '') |
|
23 | { |
||
24 | // Initialise variables |
||
25 | 30 | $this->setText($pText); |
|
26 | 30 | $this->font = new Font(); |
|
27 | 30 | } |
|
28 | |||
29 | /** |
||
30 | * Get font. |
||
31 | * |
||
32 | * @return Font |
||
33 | */ |
||
34 | 30 | public function getFont() |
|
35 | { |
||
36 | 30 | return $this->font; |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * Set font. |
||
41 | * |
||
42 | * @param Font $pFont Font |
||
43 | * |
||
44 | * @throws PhpSpreadsheetException |
||
45 | * |
||
46 | * @return ITextElement |
||
47 | */ |
||
48 | 2 | public function setFont(Font $pFont = null) |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Get hash code. |
||
57 | * |
||
58 | * @return string Hash code |
||
59 | */ |
||
60 | 10 | public function getHashCode() |
|
66 | ); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Implement PHP __clone to create a deep clone, not just a shallow copy. |
||
71 | */ |
||
72 | View Code Duplication | public function __clone() |
|
80 | } |
||
81 | } |
||
82 | } |
||
84 |
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.