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 |
||
| 16 | class Printer |
||
| 17 | { |
||
| 18 | private $output; |
||
| 19 | |||
| 20 | 1 | public function __construct(OutputInterface $output) |
|
| 24 | |||
| 25 | 1 | public function command(Host $host, string $command) |
|
| 32 | |||
| 33 | /** |
||
| 34 | * Returns a callable for use with the symfony Process->run($callable) method. |
||
| 35 | * |
||
| 36 | * @param Host $host |
||
| 37 | * @return callable A function expecting a int $type (e.g. Process::OUT or Process::ERR) and string $buffer parameters. |
||
| 38 | */ |
||
| 39 | 1 | public function callback(Host $host) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * @param string $type Process::OUT or Process::ERR |
||
| 50 | * @param Host $host |
||
| 51 | * @param string $buffer |
||
| 52 | */ |
||
| 53 | public function printBuffer(string $type, Host $host, string $buffer) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param string $type Process::OUT or Process::ERR |
||
| 62 | * @param Host $host |
||
| 63 | * @param string $line |
||
| 64 | */ |
||
| 65 | View Code Duplication | public function writeln(string $type, Host $host, string $line) |
|
| 82 | |||
| 83 | /** |
||
| 84 | * This filtering used only in Ssh\Client, but for simplify putted here. |
||
| 85 | * |
||
| 86 | * @param string $output |
||
| 87 | * @return string |
||
| 88 | */ |
||
| 89 | 1 | public static function filterOutput($output) |
|
| 93 | } |
||
| 94 |