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 |
||
16 | class SphinxService |
||
17 | { |
||
18 | protected static $_instance; |
||
19 | |||
20 | protected $client; |
||
21 | |||
22 | protected $parameters; |
||
23 | |||
24 | public function setParameters(Array $customParameters = []) |
||
38 | |||
39 | public function getParameters() |
||
47 | |||
48 | /** |
||
49 | * Factory e Configuracao padrao de um SphinxClient. |
||
50 | * |
||
51 | * @return SphinxClient |
||
52 | */ |
||
53 | public function createService() |
||
75 | |||
76 | /** |
||
77 | * Acesso ao Cliente Sphinx Server. |
||
78 | * |
||
79 | * @return Gpupo\Search\Sphinx\SphinxClient |
||
80 | */ |
||
81 | public function getClient() |
||
89 | |||
90 | /** |
||
91 | * Semelhante a *getClient()* mas com reset. |
||
92 | * |
||
93 | * @return Gpupo\Search\Sphinx\SphinxClient |
||
94 | */ |
||
95 | public function getFreshClient() |
||
99 | |||
100 | /** |
||
101 | * Limpa informações de pesquisas anteriores. |
||
102 | */ |
||
103 | public function reset() |
||
111 | |||
112 | View Code Duplication | public static function getInstance() |
|
121 | } |
||
122 |
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.