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 |
||
20 | View Code Duplication | class GetAllRetailsResult extends AbstractStructBase |
|
|
|||
21 | { |
||
22 | /** |
||
23 | * The schema |
||
24 | * Meta informations extracted from the WSDL |
||
25 | * - ref: s:schema |
||
26 | * |
||
27 | * @var \DOMDocument |
||
28 | */ |
||
29 | public $schema; |
||
30 | /** |
||
31 | * The any |
||
32 | * |
||
33 | * @var \DOMDocument |
||
34 | */ |
||
35 | public $any; |
||
36 | |||
37 | /** |
||
38 | * Constructor method for getAllRetailsResult |
||
39 | * |
||
40 | * @uses GetAllRetailsResult::setSchema() |
||
41 | * @uses GetAllRetailsResult::setAny() |
||
42 | * |
||
43 | * @param \DOMDocument $schema |
||
44 | * @param \DOMDocument $any |
||
45 | */ |
||
46 | public function __construct(\DOMDocument $schema = null, \DOMDocument $any = null) |
||
52 | |||
53 | /** |
||
54 | * Get schema value |
||
55 | * |
||
56 | * @uses \DOMDocument::loadXML() |
||
57 | * @uses \DOMDocument::hasChildNodes() |
||
58 | * @uses \DOMDocument::saveXML() |
||
59 | * @uses \DOMNode::item() |
||
60 | * @uses \Alhoqbani\SmsaWebService\Soap\Type\GetAllRetailsResult::setSchema() |
||
61 | * |
||
62 | * @param bool $asString true: returns XML string, false: returns \DOMDocument |
||
63 | * |
||
64 | * @return \DOMDocument|null |
||
65 | */ |
||
66 | public function getSchema($asString = true) |
||
79 | |||
80 | /** |
||
81 | * Set schema value |
||
82 | * |
||
83 | * @param \DOMDocument $schema |
||
84 | * |
||
85 | * @return \Alhoqbani\SmsaWebService\Soap\Type\GetAllRetailsResult |
||
86 | */ |
||
87 | public function setSchema(\DOMDocument $schema = null) |
||
93 | |||
94 | /** |
||
95 | * Get any value |
||
96 | * |
||
97 | * @uses \DOMDocument::loadXML() |
||
98 | * @uses \DOMDocument::hasChildNodes() |
||
99 | * @uses \DOMDocument::saveXML() |
||
100 | * @uses \DOMNode::item() |
||
101 | * @uses \Alhoqbani\SmsaWebService\Soap\Type\GetAllRetailsResult::setAny() |
||
102 | * |
||
103 | * @param bool $asString true: returns XML string, false: returns \DOMDocument |
||
104 | * |
||
105 | * @return \DOMDocument|null |
||
106 | */ |
||
107 | public function getAny($asString = true) |
||
120 | |||
121 | /** |
||
122 | * Set any value |
||
123 | * |
||
124 | * @param \DOMDocument $any |
||
125 | * |
||
126 | * @return \Alhoqbani\SmsaWebService\Soap\Type\GetAllRetailsResult |
||
127 | */ |
||
128 | public function setAny(\DOMDocument $any = null) |
||
134 | |||
135 | /** |
||
136 | * Method called when an object has been exported with var_export() functions |
||
137 | * It allows to return an object instantiated with the values |
||
138 | * |
||
139 | * @see AbstractStructBase::__set_state() |
||
140 | * |
||
141 | * @uses AbstractStructBase::__set_state() |
||
142 | * |
||
143 | * @param array $array the exported values |
||
144 | * |
||
145 | * @return \Alhoqbani\SmsaWebService\Soap\Type\GetAllRetailsResult |
||
146 | */ |
||
147 | public static function __set_state(array $array) |
||
151 | |||
152 | /** |
||
153 | * Method returning the class name |
||
154 | * |
||
155 | * @return string __CLASS__ |
||
156 | */ |
||
157 | public function __toString() |
||
161 | } |
||
162 |
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.