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 |
||
9 | class Emitter implements DispatcherInterface |
||
|
|||
10 | { |
||
11 | /** |
||
12 | * Dispatcher driver |
||
13 | * |
||
14 | * @var DriverInterface |
||
15 | */ |
||
16 | private $driver; |
||
17 | |||
18 | /** |
||
19 | * Logger |
||
20 | * |
||
21 | * @var LoggerInterface |
||
22 | */ |
||
23 | private $logger; |
||
24 | |||
25 | /** |
||
26 | * Create new Dispatcher |
||
27 | * |
||
28 | * @param DriverInterface $driver |
||
29 | * @param LoggerInterface $logger |
||
30 | */ |
||
31 | public function __construct(DriverInterface $driver, LoggerInterface $logger = null) |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | View Code Duplication | public function emit(MessageInterface $message) |
|
52 | |||
53 | /** |
||
54 | * Interal log method wrapper |
||
55 | * |
||
56 | * @param string $level |
||
57 | * @param string $message |
||
58 | * @param array $context |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | private function log($level, $message, array $context = array()) |
||
68 | } |
||
69 |