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 |
||
8 | class CriteriaConverter extends Converter |
||
9 | { |
||
10 | protected $queryBuilderClass = '\ezfeZPSolrQueryBuilder'; |
||
11 | |||
12 | public function __construct($handlers = array(), $queryBuilderClass = null) |
||
19 | |||
20 | /** |
||
21 | * @param Criterion $criterion |
||
22 | * @return bool |
||
23 | */ |
||
24 | public function canHandle(Criterion $criterion) |
||
35 | |||
36 | /** |
||
37 | * @param Criterion $criterion |
||
38 | * @return mixed |
||
39 | * @throws NotImplementedException |
||
40 | */ |
||
41 | View Code Duplication | public function handle(Criterion $criterion) |
|
54 | |||
55 | /** |
||
56 | * Given a Solr filter in array form (as passed to ezfeZPSolrQueryBuilder), return its string representtaion |
||
57 | * @param array $filter |
||
58 | * @return string |
||
59 | * @throws NotImplementedException |
||
60 | */ |
||
61 | public function generateQueryString($filter) |
||
71 | |||
72 | } |
||
73 |
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.