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 | View Code Duplication | class AdvancedHAxis extends MediumHAxis |
|
|
|||
6 | { |
||
7 | /** |
||
8 | * If false, will hide outermost labels rather than allow them to be cropped by the chart container. If true, |
||
9 | * will allow label cropping. |
||
10 | * |
||
11 | * @var bool |
||
12 | */ |
||
13 | protected $allowContainerBoundaryTextCufoff; |
||
14 | |||
15 | /** |
||
16 | * If true, draw the horizontal axis text at an angle, to help fit more text along the axis; if false, draw |
||
17 | * horizontal axis text upright. Default behavior is to slant text if it cannot all fit when drawn upright. |
||
18 | * Notice that this option is available only when the hAxis.textPosition is set to 'out' (which is the default). |
||
19 | * |
||
20 | * @var bool |
||
21 | */ |
||
22 | protected $slantedText; |
||
23 | |||
24 | /** |
||
25 | * The angle of the horizontal axis text, if it's drawn slanted. Ignored if hAxis.slantedText is false, or is in |
||
26 | * auto mode, and the chart decided to draw the text horizontally. |
||
27 | * |
||
28 | * @var int |
||
29 | */ |
||
30 | protected $slantedTextAngle; |
||
31 | |||
32 | /** |
||
33 | * Maximum number of levels of horizontal axis text. If axis text labels become too crowded, the server might |
||
34 | * shift neighboring labels up or down in order to fit labels closer together. This value specifies the most |
||
35 | * number of levels to use; the server can use fewer levels, if labels can fit without overlapping. |
||
36 | * |
||
37 | * @var int |
||
38 | */ |
||
39 | protected $maxAlternation; |
||
40 | |||
41 | /** |
||
42 | * Maximum number of lines allowed for the text labels. Labels can span multiple lines if they are too long, |
||
43 | * and the nuber of lines is, by default, limited by the height of the available space. |
||
44 | * |
||
45 | * @var int |
||
46 | */ |
||
47 | protected $maxTextLines; |
||
48 | |||
49 | /** |
||
50 | * Minimum horizontal spacing, in pixels, allowed between two adjacent text labels. If the labels are spaced too |
||
51 | * densely, or they are too long, the spacing can drop below this threshold, and in this case one of the |
||
52 | * label-unclutter measures will be applied (e.g, truncating the lables or dropping some of them). |
||
53 | * |
||
54 | * @var int |
||
55 | */ |
||
56 | protected $minTextSpacing; |
||
57 | |||
58 | /** |
||
59 | * How many horizontal axis labels to show, where 1 means show every label, 2 means show every other label, |
||
60 | * and so on. Default is to try to show as many labels as possible without overlapping. |
||
61 | * |
||
62 | * @var int |
||
63 | */ |
||
64 | protected $showTextEvery; |
||
65 | |||
66 | /** |
||
67 | * @param int $showTextEvery |
||
68 | * |
||
69 | * @return $this |
||
70 | */ |
||
71 | public function setShowTextEvery($showTextEvery) |
||
77 | |||
78 | /** |
||
79 | * @param bool $allowContainerBoundaryTextCufoff |
||
80 | * |
||
81 | * @return $this |
||
82 | */ |
||
83 | public function setAllowContainerBoundaryTextCufoff($allowContainerBoundaryTextCufoff) |
||
89 | |||
90 | /** |
||
91 | * @param bool $slantedText |
||
92 | * |
||
93 | * @return $this |
||
94 | */ |
||
95 | public function setSlantedText($slantedText) |
||
101 | |||
102 | /** |
||
103 | * @param int $slantedTextAngle |
||
104 | * |
||
105 | * @return $this |
||
106 | */ |
||
107 | public function setSlantedTextAngle($slantedTextAngle) |
||
113 | |||
114 | /** |
||
115 | * @param int $maxAlternation |
||
116 | * |
||
117 | * @return $this |
||
118 | */ |
||
119 | public function setMaxAlternation($maxAlternation) |
||
125 | |||
126 | /** |
||
127 | * @param int $maxTextLines |
||
128 | * |
||
129 | * @return $this |
||
130 | */ |
||
131 | public function setMaxTextLines($maxTextLines) |
||
137 | |||
138 | /** |
||
139 | * @param int $minTextSpacing |
||
140 | * |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function setMinTextSpacing($minTextSpacing) |
||
149 | } |
||
150 |
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.