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 | 6 | public function __construct(HandlerInterface $handler) |
|
| 23 | { |
||
| 24 | 6 | $this->handler = $handler; |
|
| 25 | 6 | } |
|
| 26 | |||
| 27 | 5 | public function log(string $message) |
|
| 31 | |||
| 32 | public function callback(Host $host) |
||
| 38 | |||
| 39 | 5 | public function printBuffer(Host $host, string $type, string $buffer) |
|
| 45 | |||
| 46 | 5 | View Code Duplication | public function writeln(Host $host, string $type, string $line) |
| 63 | } |
||
| 64 |