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 |
||
| 50 | class FullText extends Criterion implements CustomFieldInterface |
||
| 51 | { |
||
| 52 | /** |
||
| 53 | * Fuzziness of the fulltext search. |
||
| 54 | * |
||
| 55 | * May be a value between 0. (fuzzy) and 1. (sharp). |
||
| 56 | * |
||
| 57 | * @var float |
||
| 58 | */ |
||
| 59 | public $fuzziness = 1.; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Boost for certain fields. |
||
| 63 | * |
||
| 64 | * Array of boosts to apply for certain fields – the array should look like |
||
| 65 | * this: |
||
| 66 | * |
||
| 67 | * <code> |
||
| 68 | * array( |
||
| 69 | * 'title' => 2, |
||
| 70 | * … |
||
| 71 | * ) |
||
| 72 | * </code> |
||
| 73 | * |
||
| 74 | * @var array |
||
| 75 | */ |
||
| 76 | public $boost = []; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Analyzer configuration. |
||
| 80 | * |
||
| 81 | * @TODO: Define how this could look like |
||
| 82 | * |
||
| 83 | * @var mixed |
||
| 84 | */ |
||
| 85 | public $analyzers; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Analyzer wildcard handling configuration. |
||
| 89 | * |
||
| 90 | * @TODO: Define how this could look like |
||
| 91 | * |
||
| 92 | * @var mixed |
||
| 93 | */ |
||
| 94 | public $wildcards; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Custom field definitions to query instead of default field. |
||
| 98 | * |
||
| 99 | * @var array |
||
| 100 | */ |
||
| 101 | protected $customFields = []; |
||
| 102 | |||
| 103 | public function __construct($value, array $properties = []) |
||
| 117 | |||
| 118 | public function getSpecifications() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Set a custom field to query. |
||
| 127 | * |
||
| 128 | * Set a custom field to query for a defined field in a defined type. |
||
| 129 | * |
||
| 130 | * @param string $type |
||
| 131 | * @param string $field |
||
| 132 | * @param string $customField |
||
| 133 | */ |
||
| 134 | public function setCustomField($type, $field, $customField) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Retun custom field. |
||
| 141 | * |
||
| 142 | * If no custom field is set, return null |
||
| 143 | * |
||
| 144 | * @param string $type |
||
| 145 | * @param string $field |
||
| 146 | * |
||
| 147 | * @return mixed |
||
| 148 | */ |
||
| 149 | View Code Duplication | public function getCustomField($type, $field) |
|
| 158 | } |
||
| 159 |