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 |
||
| 12 | class TagController extends AdminBaseController |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var TagRepository |
||
| 16 | */ |
||
| 17 | private $tag; |
||
| 18 | /** |
||
| 19 | * @var TagManager |
||
| 20 | */ |
||
| 21 | private $tagManager; |
||
| 22 | |||
| 23 | public function __construct(TagRepository $tag, TagManager $tagManager) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Display a listing of the resource. |
||
| 33 | * |
||
| 34 | * @return Response |
||
| 35 | */ |
||
| 36 | public function index() |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Show the form for creating a new resource. |
||
| 45 | * |
||
| 46 | * @return Response |
||
| 47 | */ |
||
| 48 | public function create() |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Store a newly created resource in storage. |
||
| 57 | * |
||
| 58 | * @param CreateTagRequest $request |
||
| 59 | * @return Response |
||
| 60 | */ |
||
| 61 | public function store(CreateTagRequest $request) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Show the form for editing the specified resource. |
||
| 71 | * |
||
| 72 | * @param Tag $tag |
||
| 73 | * @return Response |
||
| 74 | */ |
||
| 75 | public function edit(Tag $tag) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Update the specified resource in storage. |
||
| 84 | * |
||
| 85 | * @param Tag $tag |
||
| 86 | * @param UpdateTagRequest $request |
||
| 87 | * @return Response |
||
| 88 | */ |
||
| 89 | View Code Duplication | public function update(Tag $tag, UpdateTagRequest $request) |
|
| 96 | |||
| 97 | /** |
||
| 98 | * Remove the specified resource from storage. |
||
| 99 | * |
||
| 100 | * @param Tag $tag |
||
| 101 | * @return Response |
||
| 102 | */ |
||
| 103 | View Code Duplication | public function destroy(Tag $tag) |
|
| 110 | |||
| 111 | private function formatNamespaces(array $namespaces) |
||
| 120 | } |
||
| 121 |