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 | class Locale |
||
| 22 | { |
||
| 23 | private $container; |
||
| 24 | private $locale; |
||
| 25 | |||
| 26 | |||
| 27 | /** |
||
| 28 | * Initializes the object |
||
| 29 | * |
||
| 30 | * @param ContainerInterface $container Dependency container |
||
| 31 | */ |
||
| 32 | public function __construct( ContainerInterface $container ) |
||
| 36 | |||
| 37 | |||
| 38 | /** |
||
| 39 | * Returns the locale item for the current request |
||
| 40 | * |
||
| 41 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
| 42 | * @param array $attributes Associative list of URL parameter |
||
| 43 | * @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
||
| 44 | */ |
||
| 45 | public function get( \Aimeos\MShop\Context\Item\Iface $context, array $attributes ) |
||
| 61 | |||
| 62 | |||
| 63 | /** |
||
| 64 | * Returns the locale item for the current request |
||
| 65 | * |
||
| 66 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
| 67 | * @param string $site Unique site code |
||
| 68 | * @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
||
| 69 | */ |
||
| 70 | View Code Duplication | public function getBackend( \Aimeos\MShop\Context\Item\Iface $context, $site ) |
|
| 87 | } |
||
| 88 |
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.