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 |
||
20 | class MessagesController extends Controller |
||
21 | { |
||
22 | public function index(Request $request) |
||
|
|||
23 | { |
||
24 | $currentUserId = Auth::id(); |
||
25 | $threads = Thread::participateBy($currentUserId); |
||
26 | |||
27 | // @todo Refazer essa parte |
||
28 | // if (Auth::user()->newThreadsCount() == 0) { |
||
29 | // Auth::user()->message_count = 0; |
||
30 | // Auth::user()->save(); |
||
31 | // } |
||
32 | |||
33 | $currentActor = Auth::user(); |
||
34 | |||
35 | |||
36 | return view( |
||
37 | 'transmissor::users.messages.index', |
||
38 | compact( |
||
39 | 'threads', |
||
40 | 'currentUserId', |
||
41 | 'currentActor' |
||
42 | ) |
||
43 | ); |
||
44 | } |
||
45 | |||
46 | View Code Duplication | public function show($id) |
|
64 | |||
65 | View Code Duplication | public function create($id = null) |
|
79 | |||
80 | View Code Duplication | public function createSecureMessage($id) |
|
81 | { |
||
82 | // @todo Fazer com as seguintes opcoes |
||
83 | // timePraAutoDestruicao |
||
84 | // Grava em disco ou só memoria |
||
85 | // Criptografia ponta a ponta com limite de data |
||
86 | $recipient = User::findOrFail($id); |
||
87 | |||
88 | $thread = Thread::between([$recipient->id, Auth::id()])->first(); |
||
89 | if ($thread) { |
||
90 | return redirect()->route('profile.transmissor.messages.show', $thread->id); |
||
91 | } |
||
92 | |||
93 | return view('transmissor::users.messages.create', compact('recipient')); |
||
94 | } |
||
95 | |||
96 | View Code Duplication | public function store(MessageRequest $request, Markdown $markdown) |
|
145 | } |
||
146 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.