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 FacetConverter extends Converter |
||
9 | { |
||
10 | /** |
||
11 | * Check if the FacetBuilder can be handled by any of the available handlers. |
||
12 | * |
||
13 | * @param FacetBuilder $facetBuilder |
||
14 | * @return bool |
||
15 | */ |
||
16 | public function canHandle(FacetBuilder $facetBuilder) |
||
27 | |||
28 | /** |
||
29 | * Map facet builder value to a proper SOLR representation. |
||
30 | * |
||
31 | * @param FacetBuilder $facetBuilder |
||
32 | * @return array |
||
33 | * |
||
34 | * @throws NotImplementedException |
||
35 | */ |
||
36 | View Code Duplication | public function handle(FacetBuilder $facetBuilder) |
|
49 | |||
50 | /** |
||
51 | * Map eZFind facet results to correct facet handler. |
||
52 | * |
||
53 | * @param FacetBuilder $facetBuilder |
||
54 | * @param array $fields |
||
55 | * @param array $queries |
||
56 | * @param array $dates |
||
57 | * @param array $ranges |
||
58 | * @return \eZ\Publish\API\Repository\Values\Content\Search\Facet |
||
59 | * |
||
60 | * @throws NotImplementedException |
||
61 | */ |
||
62 | public function buildFacet(FacetBuilder $facetBuilder, $fields = [], $queries = [], $dates = [], $ranges = []) |
||
75 | } |
||
76 |
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.