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 |
||
15 | class Logger |
||
16 | { |
||
17 | /** |
||
18 | * @var HandlerInterface |
||
19 | */ |
||
20 | private $handler; |
||
21 | |||
22 | 9 | public function __construct(HandlerInterface $handler) |
|
23 | { |
||
24 | 9 | $this->handler = $handler; |
|
25 | 9 | } |
|
26 | |||
27 | 8 | public function log(string $message) |
|
31 | |||
32 | public function callback(Host $host) |
||
38 | |||
39 | 8 | public function printBuffer(Host $host, string $type, string $buffer) |
|
45 | |||
46 | 8 | View Code Duplication | public function writeln(Host $host, string $type, string $line) |
63 | } |
||
64 |