Total Complexity | 16 |
Total Lines | 206 |
Duplicated Lines | 3.88 % |
Coverage | 84.21% |
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 |
||
5 | class PageMargins |
||
6 | { |
||
7 | /** |
||
8 | * Left. |
||
9 | * |
||
10 | * @var float |
||
11 | */ |
||
12 | private $left = 0.7; |
||
13 | |||
14 | /** |
||
15 | * Right. |
||
16 | * |
||
17 | * @var float |
||
18 | */ |
||
19 | private $right = 0.7; |
||
20 | |||
21 | /** |
||
22 | * Top. |
||
23 | * |
||
24 | * @var float |
||
25 | */ |
||
26 | private $top = 0.75; |
||
27 | |||
28 | /** |
||
29 | * Bottom. |
||
30 | * |
||
31 | * @var float |
||
32 | */ |
||
33 | private $bottom = 0.75; |
||
34 | |||
35 | /** |
||
36 | * Header. |
||
37 | * |
||
38 | * @var float |
||
39 | */ |
||
40 | private $header = 0.3; |
||
41 | |||
42 | /** |
||
43 | * Footer. |
||
44 | * |
||
45 | * @var float |
||
46 | */ |
||
47 | private $footer = 0.3; |
||
48 | |||
49 | /** |
||
50 | * Create a new PageMargins. |
||
51 | */ |
||
52 | 153 | public function __construct() |
|
53 | { |
||
54 | 153 | } |
|
55 | |||
56 | /** |
||
57 | * Get Left. |
||
58 | * |
||
59 | * @return float |
||
60 | */ |
||
61 | 62 | public function getLeft() |
|
62 | { |
||
63 | 62 | return $this->left; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Set Left. |
||
68 | * |
||
69 | * @param float $pValue |
||
70 | * |
||
71 | * @return PageMargins |
||
72 | */ |
||
73 | 17 | public function setLeft($pValue) |
|
74 | { |
||
75 | 17 | $this->left = $pValue; |
|
76 | |||
77 | 17 | return $this; |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * Get Right. |
||
82 | * |
||
83 | * @return float |
||
84 | */ |
||
85 | 62 | public function getRight() |
|
86 | { |
||
87 | 62 | return $this->right; |
|
88 | } |
||
89 | |||
90 | /** |
||
91 | * Set Right. |
||
92 | * |
||
93 | * @param float $pValue |
||
94 | * |
||
95 | * @return PageMargins |
||
96 | */ |
||
97 | 17 | public function setRight($pValue) |
|
98 | { |
||
99 | 17 | $this->right = $pValue; |
|
100 | |||
101 | 17 | return $this; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * Get Top. |
||
106 | * |
||
107 | * @return float |
||
108 | */ |
||
109 | 62 | public function getTop() |
|
110 | { |
||
111 | 62 | return $this->top; |
|
112 | } |
||
113 | |||
114 | /** |
||
115 | * Set Top. |
||
116 | * |
||
117 | * @param float $pValue |
||
118 | * |
||
119 | * @return PageMargins |
||
120 | */ |
||
121 | 17 | public function setTop($pValue) |
|
122 | { |
||
123 | 17 | $this->top = $pValue; |
|
124 | |||
125 | 17 | return $this; |
|
126 | } |
||
127 | |||
128 | /** |
||
129 | * Get Bottom. |
||
130 | * |
||
131 | * @return float |
||
132 | */ |
||
133 | 62 | public function getBottom() |
|
134 | { |
||
135 | 62 | return $this->bottom; |
|
136 | } |
||
137 | |||
138 | /** |
||
139 | * Set Bottom. |
||
140 | * |
||
141 | * @param float $pValue |
||
142 | * |
||
143 | * @return PageMargins |
||
144 | */ |
||
145 | 17 | public function setBottom($pValue) |
|
146 | { |
||
147 | 17 | $this->bottom = $pValue; |
|
148 | |||
149 | 17 | return $this; |
|
150 | } |
||
151 | |||
152 | /** |
||
153 | * Get Header. |
||
154 | * |
||
155 | * @return float |
||
156 | */ |
||
157 | 58 | public function getHeader() |
|
158 | { |
||
159 | 58 | return $this->header; |
|
160 | } |
||
161 | |||
162 | /** |
||
163 | * Set Header. |
||
164 | * |
||
165 | * @param float $pValue |
||
166 | * |
||
167 | * @return PageMargins |
||
168 | */ |
||
169 | 29 | public function setHeader($pValue) |
|
170 | { |
||
171 | 29 | $this->header = $pValue; |
|
172 | |||
173 | 29 | return $this; |
|
174 | } |
||
175 | |||
176 | /** |
||
177 | * Get Footer. |
||
178 | * |
||
179 | * @return float |
||
180 | */ |
||
181 | 58 | public function getFooter() |
|
182 | { |
||
183 | 58 | return $this->footer; |
|
184 | } |
||
185 | |||
186 | /** |
||
187 | * Set Footer. |
||
188 | * |
||
189 | * @param float $pValue |
||
190 | * |
||
191 | * @return PageMargins |
||
192 | */ |
||
193 | 29 | public function setFooter($pValue) |
|
194 | { |
||
195 | 29 | $this->footer = $pValue; |
|
196 | |||
197 | 29 | return $this; |
|
198 | } |
||
199 | |||
200 | /** |
||
201 | * Implement PHP __clone to create a deep clone, not just a shallow copy. |
||
202 | */ |
||
203 | View Code Duplication | public function __clone() |
|
211 | } |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 |
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.