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 |
||
17 | class Handler extends ExceptionHandler |
||
18 | { |
||
19 | /** |
||
20 | * A list of the exception types that should not be reported. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $dontReport = [ |
||
25 | // 'Symfony\Component\HttpKernel\Exception\HttpException', |
||
26 | \Illuminate\Http\Exception\HttpResponseException::class, |
||
27 | ValidationException::class, |
||
28 | AuthorizationException::class, |
||
29 | HttpResponseException ::class, |
||
30 | ModelNotFoundException::class, |
||
31 | \Symfony\Component\HttpKernel\Exception\HttpException::class, |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * Report or log an exception. |
||
36 | * |
||
37 | * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
||
38 | * |
||
39 | * @param \Exception $e |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | public function report(Exception $e) |
||
58 | |||
59 | /** |
||
60 | * Render an exception into an HTTP response. |
||
61 | * |
||
62 | * @param type $request |
||
63 | * @param Exception $e |
||
64 | * |
||
65 | * @return type mixed |
||
66 | */ |
||
67 | public function render($request, Exception $e) |
||
80 | |||
81 | /** |
||
82 | * Function to render 500 error page. |
||
83 | * |
||
84 | * @param type $request |
||
85 | * @param type $e |
||
86 | * |
||
87 | * @return type mixed |
||
88 | */ |
||
89 | public function render500($request, $e) |
||
100 | |||
101 | /** |
||
102 | * Function to render 404 error page. |
||
103 | * |
||
104 | * @param type $request |
||
105 | * @param type $e |
||
106 | * |
||
107 | * @return type mixed |
||
108 | */ |
||
109 | public function render404($request, $e) |
||
125 | |||
126 | /** |
||
127 | * Function to render database connection failed. |
||
128 | * |
||
129 | * @param type $request |
||
130 | * @param type $e |
||
131 | * |
||
132 | * @return type mixed |
||
133 | */ |
||
134 | public function renderDB($request, $e) |
||
146 | |||
147 | /** |
||
148 | * Common finction to render both types of codes. |
||
149 | * |
||
150 | * @param type $request |
||
151 | * @param type $e |
||
152 | * |
||
153 | * @return type mixed |
||
154 | */ |
||
155 | public function common($request, $e) |
||
180 | } |
||
181 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.