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 |
||
| 32 | View Code Duplication | class OutboundDimensions implements DimensionsInterface |
|
|
|
|||
| 33 | { |
||
| 34 | /** |
||
| 35 | * @var Dimensions |
||
| 36 | */ |
||
| 37 | private $originalDimensions; |
||
| 38 | /** |
||
| 39 | * @var Dimensions |
||
| 40 | */ |
||
| 41 | private $targetDimensions; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * OutboundDimensions constructor. |
||
| 45 | * |
||
| 46 | * @param Dimensions $originalDimensions the original image dimensions |
||
| 47 | * @param Dimensions $targetDimensions the target image dimensions |
||
| 48 | */ |
||
| 49 | public function __construct(Dimensions $originalDimensions, Dimensions $targetDimensions) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return int |
||
| 57 | */ |
||
| 58 | public function getWidth() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return float|int |
||
| 73 | */ |
||
| 74 | public function getHeight() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @return bool whether image is in the portrait orientation |
||
| 89 | */ |
||
| 90 | private function isVertical() |
||
| 94 | |||
| 95 | /** |
||
| 96 | * {@inheritdoc} |
||
| 97 | */ |
||
| 98 | public function getRatio() |
||
| 102 | } |
||
| 103 |
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.