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 |
||
25 | class Field extends FieldBase |
||
26 | { |
||
27 | /** |
||
28 | * Field converter registry. |
||
29 | * |
||
30 | * @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry |
||
31 | */ |
||
32 | protected $fieldConverterRegistry; |
||
33 | |||
34 | /** |
||
35 | * Field value converter. |
||
36 | * |
||
37 | * @var \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldValue\Converter |
||
38 | */ |
||
39 | protected $fieldValueConverter; |
||
40 | |||
41 | /** |
||
42 | * Transformation processor. |
||
43 | * |
||
44 | * @var \eZ\Publish\Core\Persistence\TransformationProcessor |
||
45 | */ |
||
46 | protected $transformationProcessor; |
||
47 | |||
48 | public function __construct( |
||
62 | |||
63 | /** |
||
64 | * Check if this criterion handler accepts to handle the given criterion. |
||
65 | * |
||
66 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function accept(Criterion $criterion) |
||
74 | |||
75 | /** |
||
76 | * Returns relevant field information for the specified field. |
||
77 | * |
||
78 | * The returned information is returned as an array of the attribute |
||
79 | * identifier and the sort column, which should be used. |
||
80 | * |
||
81 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If no searchable fields are found for the given $fieldIdentifier. |
||
82 | * @throws \RuntimeException if no converter is found |
||
83 | * |
||
84 | * @param string $fieldIdentifier |
||
85 | * |
||
86 | * @return array |
||
87 | * |
||
88 | * @throws \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound |
||
89 | */ |
||
90 | protected function getFieldsInformation($fieldIdentifier) |
||
117 | |||
118 | /** |
||
119 | * Generate query expression for a Criterion this handler accepts. |
||
120 | * |
||
121 | * accept() must be called before calling this method. |
||
122 | * |
||
123 | * @throws \eZ\Publish\API\Repository\Exceptions\NotImplementedException If no searchable fields are found for the given criterion target. |
||
124 | * |
||
125 | * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter |
||
126 | * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query |
||
127 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
128 | * @param array $languageSettings |
||
129 | * |
||
130 | * @return \eZ\Publish\Core\Persistence\Database\Expression |
||
131 | * |
||
132 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
133 | * @throws \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound |
||
134 | */ |
||
135 | public function handle( |
||
181 | } |
||
182 |
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.