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 Comodojo\RpcClient\Utils; |
||
23 | View Code Duplication | class NullLogger implements LoggerInterface { |
|
|
|||
24 | |||
25 | /** |
||
26 | * emergency |
||
27 | * |
||
28 | * @param string $message |
||
29 | * @param array $context |
||
30 | * |
||
31 | * @return null |
||
32 | */ |
||
33 | public function emergency($message, array $context = array()) { return; } |
||
34 | |||
35 | /** |
||
36 | * alert |
||
37 | * |
||
38 | * @param string $message |
||
39 | * @param array $context |
||
40 | * |
||
41 | * @return null |
||
42 | */ |
||
43 | public function alert($message, array $context = array()) { return; } |
||
44 | |||
45 | /** |
||
46 | * critical |
||
47 | * |
||
48 | * @param string $message |
||
49 | * @param array $context |
||
50 | * |
||
51 | * @return null |
||
52 | */ |
||
53 | public function critical($message, array $context = array()) { return; } |
||
54 | |||
55 | /** |
||
56 | * error |
||
57 | * |
||
58 | * @param string $message |
||
59 | * @param array $context |
||
60 | * |
||
61 | * @return null |
||
62 | */ |
||
63 | public function error($message, array $context = array()) { return; } |
||
64 | |||
65 | /** |
||
66 | * warning |
||
67 | * |
||
68 | * @param string $message |
||
69 | * @param array $context |
||
70 | * |
||
71 | * @return null |
||
72 | */ |
||
73 | public function warning($message, array $context = array()) { return; } |
||
74 | |||
75 | /** |
||
76 | * notice |
||
77 | * |
||
78 | * @param string $message |
||
79 | * @param array $context |
||
80 | * |
||
81 | * @return null |
||
82 | */ |
||
83 | public function notice($message, array $context = array()) { return; } |
||
84 | |||
85 | /** |
||
86 | * info |
||
87 | * |
||
88 | * @param string $message |
||
89 | * @param array $context |
||
90 | * |
||
91 | * @return null |
||
92 | */ |
||
93 | public function info($message, array $context = array()) { return; } |
||
94 | |||
95 | /** |
||
96 | * debug |
||
97 | * |
||
98 | * @param string $message |
||
99 | * @param array $context |
||
100 | * |
||
101 | * @return null |
||
102 | */ |
||
103 | public function debug($message, array $context = array()) { return; } |
||
104 | |||
105 | /** |
||
106 | * log |
||
107 | * |
||
108 | * @param mixed $level |
||
109 | * @param string $message |
||
110 | * @param array $context |
||
111 | * |
||
112 | * @return null |
||
113 | */ |
||
114 | public function log($level, $message, array $context = array()) { return; } |
||
115 | |||
116 | } |
||
117 |
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.