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 |
||
41 | class Logger extends ObjectAbstract implements LoggerInterface, LogEntryPrototypeInterface |
||
42 | { |
||
43 | use LoggerTrait, LogEntryPrototypeTrait, ExtendedLoggerTrait; |
||
44 | |||
45 | /** |
||
46 | * Instantiate with default channel name and log entry prototype |
||
47 | * |
||
48 | * @param string $channel default channel |
||
49 | * @param LogEntryInterface $entryPrototype if any |
||
50 | * @access protected |
||
51 | */ |
||
52 | public function __construct( |
||
59 | |||
60 | /** |
||
61 | * Set/With current channel, followed by any log() method |
||
62 | * |
||
63 | * @param string $channel current channel |
||
64 | * @return $this |
||
65 | * @access protected |
||
66 | */ |
||
67 | public function with(/*# string */ $channel) |
||
72 | |||
73 | /** |
||
74 | * Logs with an arbitrary level. |
||
75 | * |
||
76 | * @param mixed $level |
||
77 | * @param string $message |
||
78 | * @param array $context |
||
79 | * @return null |
||
80 | */ |
||
81 | public function log($level, $message, array $context = array()) |
||
100 | |||
101 | /** |
||
102 | * Add handler to the channel with priority |
||
103 | * |
||
104 | * @param string $level the level this handler is handling |
||
105 | * @param callable $handler |
||
106 | * @param string $channel channel to listen to |
||
107 | * @param int $priority |
||
108 | * @return $this |
||
109 | * @access public |
||
110 | * @since 2.0.1 added level param |
||
111 | * @api |
||
112 | */ |
||
113 | public function addHandler( |
||
135 | |||
136 | /** |
||
137 | * Remove this handler from the channel |
||
138 | * |
||
139 | * if $channel == '', then remove this handler from all channels |
||
140 | * |
||
141 | * @param callable|string $handlerOrClassname |
||
142 | * @param string $channel |
||
143 | * @return $this |
||
144 | * @access public |
||
145 | * @api |
||
146 | */ |
||
147 | public function removeHandler($handlerOrClassname, $channel = '') |
||
151 | |||
152 | /** |
||
153 | * Add processor to the channel with priority |
||
154 | * |
||
155 | * @param callable $processor |
||
156 | * @param string $channel channel to listen to |
||
157 | * @param int $priority |
||
158 | * @return $this |
||
159 | * @access public |
||
160 | * @api |
||
161 | */ |
||
162 | public function addProcessor( |
||
174 | |||
175 | /** |
||
176 | * Remove this $processor from $channel |
||
177 | * |
||
178 | * if $channel == '', then remove processor from all channels |
||
179 | * |
||
180 | * @param callable|string $processorOrClassname |
||
181 | * @param string $channel |
||
182 | * @return $this |
||
183 | * @access public |
||
184 | * @api |
||
185 | */ |
||
186 | public function removeProcessor($processorOrClassname, $channel = '') |
||
194 | } |
||
195 |