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