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 |
||
| 14 | class RootController extends Controller |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Create a new docs controller instance. |
||
| 18 | */ |
||
| 19 | public function __construct() |
||
| 22 | |||
| 23 | /** |
||
| 24 | * topアクション. |
||
| 25 | * |
||
| 26 | * @param Requeat $request リクエスト |
||
| 27 | * |
||
| 28 | * @return view root_topテンプレート |
||
| 29 | */ |
||
| 30 | public function topAction(Request $request) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * homeアクション. |
||
| 41 | * |
||
| 42 | * @param Requeat $request リクエスト |
||
| 43 | * |
||
| 44 | * @return view root_homeテンプレート |
||
| 45 | */ |
||
| 46 | View Code Duplication | public function homeAction(Request $request) |
|
| 54 | |||
| 55 | /** |
||
| 56 | * contentsアクション. |
||
| 57 | * |
||
| 58 | * @param Requeat $request リクエスト |
||
| 59 | * |
||
| 60 | * @return view root_contentsテンプレート |
||
| 61 | */ |
||
| 62 | public function contentsAction(Request $request) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * docsアクション. |
||
| 74 | * |
||
| 75 | * @param Requeat $request リクエスト |
||
| 76 | * |
||
| 77 | * @return view root_docsテンプレート |
||
| 78 | */ |
||
| 79 | View Code Duplication | public function docsAction(Request $request) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * devアクション. |
||
| 90 | * |
||
| 91 | * @param Requeat $request リクエスト |
||
| 92 | * |
||
| 93 | * @return view root_devテンプレート |
||
| 94 | */ |
||
| 95 | View Code Duplication | public function devAction(Request $request) |
|
| 103 | } |
||
| 104 |
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.