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 |
||
22 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html |
||
23 | */ |
||
24 | class ConstantScoreQuery implements BuilderInterface |
||
25 | { |
||
26 | use ParametersTrait; |
||
27 | |||
28 | public function __construct( |
||
29 | private BuilderInterface $query, |
||
|
|||
30 | array $parameters = [] |
||
31 | ) { |
||
32 | $this->setParameters($parameters); |
||
33 | } |
||
34 | |||
35 | public function getType(): string |
||
36 | { |
||
37 | return 'constant_score'; |
||
38 | } |
||
39 | |||
40 | public function toArray(): array |
||
41 | { |
||
42 | $query = [ |
||
43 | 'filter' => $this->query->toArray(), |
||
44 | ]; |
||
45 | |||
46 | $output = $this->processArray($query); |
||
47 | |||
48 | return [$this->getType() => $output]; |
||
49 | } |
||
50 | } |
||
51 |