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 |
||
| 24 | final class RaListingSearchQuery implements HttpQuery |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $institution; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var int |
||
| 33 | */ |
||
| 34 | private $pageNumber; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string|null |
||
| 38 | */ |
||
| 39 | private $orderBy = 'commonName'; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string|null |
||
| 43 | */ |
||
| 44 | private $orderDirection = 'asc'; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param string $institution |
||
| 48 | * @param int $pageNumber |
||
| 49 | */ |
||
| 50 | View Code Duplication | public function __construct($institution, $pageNumber) |
|
| 60 | |||
| 61 | /** |
||
| 62 | * @param string $orderBy |
||
| 63 | * @return RaListingSearchQuery |
||
| 64 | */ |
||
| 65 | public function setOrderBy($orderBy) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param string|null $orderDirection |
||
| 76 | * @return RaListingSearchQuery |
||
| 77 | */ |
||
| 78 | View Code Duplication | public function setOrderDirection($orderDirection) |
|
| 89 | |||
| 90 | View Code Duplication | private function assertNonEmptyString($value, $parameterName) |
|
| 100 | |||
| 101 | public function toHttpQuery() |
||
| 117 | } |
||
| 118 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.