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 |
||
26 | class AdminController extends Controller |
||
27 | { |
||
28 | use AuthorizesRequests; |
||
29 | |||
30 | |||
31 | /** |
||
32 | * Returns the initial HTML view for the admin interface. |
||
33 | * |
||
34 | * @return Response Response object containing the generated output |
||
35 | */ |
||
36 | public function indexAction() |
||
50 | |||
51 | |||
52 | /** |
||
53 | * Returns the version of the Aimeos package |
||
54 | * |
||
55 | * @return string Version string |
||
56 | */ |
||
57 | protected function getVersion() |
||
72 | |||
73 | |||
74 | /** |
||
75 | * Sets the locale item in the given context |
||
76 | * |
||
77 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
78 | * @param string $sitecode Unique site code |
||
79 | * @param string $lang ISO language code, e.g. "en" or "en_GB" |
||
80 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
81 | */ |
||
82 | View Code Duplication | protected function setLocale( \Aimeos\MShop\Context\Item\Iface $context, $sitecode = 'default', $lang = null ) |
|
102 | } |
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.