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-script-query.html |
||
23 | */ |
||
24 | class ScriptQuery implements BuilderInterface |
||
25 | { |
||
26 | use ParametersTrait; |
||
27 | |||
28 | public function __construct(private string $script, array $parameters = []) |
||
|
|||
29 | { |
||
30 | $this->setParameters($parameters); |
||
31 | } |
||
32 | |||
33 | public function getType(): string |
||
34 | { |
||
35 | return 'script'; |
||
36 | } |
||
37 | |||
38 | public function toArray(): array |
||
39 | { |
||
40 | $query = ['inline' => $this->script]; |
||
41 | $output = $this->processArray($query); |
||
42 | |||
43 | return [$this->getType() => ['script' => $output]]; |
||
44 | } |
||
45 | } |
||
46 |