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 |
||
30 | class See |
||
31 | { |
||
32 | /** |
||
33 | * @var FeFactory |
||
34 | */ |
||
35 | private $factory; |
||
36 | |||
37 | /** |
||
38 | * @var SoapClient |
||
39 | */ |
||
40 | private $wsClient; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | private $builders; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | private $summarys; |
||
51 | |||
52 | /** |
||
53 | * @var SignedXml |
||
54 | */ |
||
55 | private $signer; |
||
56 | |||
57 | /** |
||
58 | * @var ErrorCodeProviderInterface |
||
59 | */ |
||
60 | private $codeProvider; |
||
61 | |||
62 | /** |
||
63 | * Twig Render Options. |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | private $options = ['autoescape' => false]; |
||
68 | |||
69 | /** |
||
70 | * See constructor. |
||
71 | */ |
||
72 | 30 | public function __construct() |
|
90 | |||
91 | /** |
||
92 | * Set Xml Builder Options. |
||
93 | * |
||
94 | * @param array $options |
||
95 | */ |
||
96 | 30 | public function setBuilderOptions(array $options) |
|
100 | |||
101 | /** |
||
102 | * @param string $directory |
||
103 | */ |
||
104 | 18 | public function setCachePath($directory) |
|
108 | |||
109 | /** |
||
110 | * @param string $certificate |
||
111 | */ |
||
112 | 30 | public function setCertificate($certificate) |
|
116 | |||
117 | /** |
||
118 | * @param string $user |
||
119 | * @param string $password |
||
120 | */ |
||
121 | 30 | public function setCredentials($user, $password) |
|
125 | |||
126 | /** |
||
127 | * @param string $service |
||
128 | */ |
||
129 | 30 | public function setService($service) |
|
133 | |||
134 | /** |
||
135 | * Set error code provider. |
||
136 | * |
||
137 | * @param ErrorCodeProviderInterface $codeProvider |
||
138 | */ |
||
139 | 18 | public function setCodeProvider($codeProvider) |
|
143 | |||
144 | /** |
||
145 | * Get signed xml from document. |
||
146 | * |
||
147 | * @param DocumentInterface $document |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | 10 | public function getXmlSigned(DocumentInterface $document) |
|
159 | |||
160 | /** |
||
161 | * Envia documento. |
||
162 | * |
||
163 | * @param DocumentInterface $document |
||
164 | * |
||
165 | * @return Model\Response\BaseResult |
||
166 | */ |
||
167 | 18 | View Code Duplication | public function send(DocumentInterface $document) |
|
|||
168 | { |
||
169 | 18 | $classDoc = get_class($document); |
|
170 | 18 | $this->factory |
|
171 | 18 | ->setBuilder($this->getBuilder($classDoc)) |
|
172 | 18 | ->setSender($this->getSender($classDoc)); |
|
173 | |||
174 | 18 | return $this->factory->send($document); |
|
175 | } |
||
176 | |||
177 | // Solicitar CDR desde un XML ya generado. by thefantas |
||
178 | View Code Duplication | public function sendForce(DocumentInterface $document, $dir_xml) |
|
187 | // Generar solo XML. by thefantas |
||
188 | public function genXML(DocumentInterface $document) |
||
196 | |||
197 | /** |
||
198 | * @param $ticket |
||
199 | * |
||
200 | * @return Model\Response\StatusResult |
||
201 | */ |
||
202 | 2 | public function getStatus($ticket) |
|
209 | |||
210 | /** |
||
211 | * @return FeFactory |
||
212 | */ |
||
213 | 6 | public function getFactory() |
|
217 | |||
218 | /** |
||
219 | * @param string $class |
||
220 | * |
||
221 | * @return BuilderInterface |
||
222 | */ |
||
223 | 28 | private function getBuilder($class) |
|
229 | |||
230 | /** |
||
231 | * @param string $class |
||
232 | * |
||
233 | * @return SenderInterface |
||
234 | */ |
||
235 | 18 | private function getSender($class) |
|
245 | } |
||
246 |
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.