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 namespace Anomaly\Streams\Platform\Exception; |
||
16 | class ExceptionHandler extends NewExceptionHandler |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * A list of the exception types that should not be reported. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $dontReport = [ |
||
25 | \Illuminate\Auth\AuthenticationException::class, |
||
26 | \Illuminate\Auth\Access\AuthorizationException::class, |
||
27 | \Symfony\Component\HttpKernel\Exception\HttpException::class, |
||
28 | \Illuminate\Database\Eloquent\ModelNotFoundException::class, |
||
29 | \Illuminate\Session\TokenMismatchException::class, |
||
30 | \Illuminate\Validation\ValidationException::class, |
||
31 | ]; |
||
32 | |||
33 | /** |
||
34 | * Render an exception into an HTTP response. |
||
35 | * |
||
36 | * @param Request $request |
||
37 | * @param Exception $e |
||
38 | * @return Response |
||
39 | */ |
||
40 | public function render($request, Exception $e) |
||
58 | |||
59 | /** |
||
60 | * Convert an authentication exception into an unauthenticated response. |
||
61 | * |
||
62 | * @param \Illuminate\Http\Request $request |
||
63 | * @param \Illuminate\Auth\AuthenticationException $exception |
||
64 | * @return \Illuminate\Http\Response |
||
65 | */ |
||
66 | protected function unauthenticated($request, AuthenticationException $exception) |
||
78 | } |
||
79 |
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.