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 |
||
| 11 | class NotificationController extends Controller |
||
| 12 | { |
||
| 13 | |||
| 14 | use Helpers; |
||
| 15 | |||
| 16 | public function __construct() { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Display a listing of all notifications |
||
| 21 | * |
||
| 22 | * @return \Illuminate\Http\Response |
||
| 23 | */ |
||
| 24 | public function index(Request $request, $type = null) |
||
| 25 | { |
||
| 26 | if ($type === 'archive') |
||
| 27 | { |
||
| 28 | $notifications = Notification::IsArchived($request)->get(); |
||
|
|
|||
| 29 | } |
||
| 30 | else { |
||
| 31 | $notifications = Notification::IsUnread()->get(); |
||
| 32 | } |
||
| 33 | return $notifications; |
||
| 34 | } |
||
| 35 | |||
| 36 | public function update(Request $request, $id, $action) |
||
| 67 | |||
| 68 | } |
||
| 69 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.