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 |
||
14 | class LoggerHandler implements ExceptionHandler, IHandler |
||
15 | { |
||
16 | /** |
||
17 | * app exception handler. |
||
18 | * |
||
19 | * @var \Illuminate\Contracts\Debug\ExceptionHandler |
||
20 | */ |
||
21 | protected $exceptionHandler; |
||
22 | |||
23 | /** |
||
24 | * $debuggerManager. |
||
25 | * |
||
26 | * @var \Recca0120\LaravelTracy\DebuggerManager |
||
27 | */ |
||
28 | protected $debuggerManager; |
||
29 | |||
30 | /** |
||
31 | * __construct. |
||
32 | * |
||
33 | * @param \Illuminate\Contracts\Debug\ExceptionHandler $exceptionHandler |
||
34 | * @param \Recca0120\LaravelTracy\DebuggerManager $debuggerManager |
||
35 | */ |
||
36 | 1 | public function __construct(ExceptionHandler $exceptionHandler, DebuggerManager $debuggerManager) |
|
41 | |||
42 | /** |
||
43 | * Report or log an exception. |
||
44 | * |
||
45 | * @param \Exception $e |
||
46 | */ |
||
47 | public function report(Exception $e) |
||
51 | |||
52 | /** |
||
53 | * inject sending of email with error and render an exception into an HTTP response. |
||
54 | * |
||
55 | * @param \Illuminate\Http\Request $request |
||
56 | * @param \Exception $e |
||
57 | * @return \Symfony\Component\HttpFoundation\Response |
||
58 | */ |
||
59 | public function render($request, Exception $e) |
||
67 | |||
68 | /** |
||
69 | * Render an exception to the console. |
||
70 | * |
||
71 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
72 | * @param \Exception $e |
||
73 | */ |
||
74 | public function renderForConsole($output, Exception $e) |
||
78 | |||
79 | /** |
||
80 | * shouldRenderException. |
||
81 | * |
||
82 | * @param \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response $response |
||
83 | * @return bool |
||
84 | */ |
||
85 | View Code Duplication | protected function shouldRenderException($response) |
|
105 | } |
||
106 |
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.