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