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 |
||
| 13 | class Informer |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var \Deployer\Console\Output\OutputWatcher |
||
| 17 | */ |
||
| 18 | private $output; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param \Deployer\Console\Output\OutputWatcher $output |
||
| 22 | */ |
||
| 23 | 18 | public function __construct(OutputWatcher $output) |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @param string $taskName |
||
| 30 | */ |
||
| 31 | 15 | public function startTask($taskName) |
|
| 45 | |||
| 46 | /** |
||
| 47 | * Print task was ok. |
||
| 48 | */ |
||
| 49 | 16 | public function endTask() |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @param string $serverName |
||
| 60 | */ |
||
| 61 | 15 | public function onServer($serverName) |
|
| 67 | |||
| 68 | /** |
||
| 69 | * @param string $serverName |
||
| 70 | */ |
||
| 71 | 14 | public function endOnServer($serverName) |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Print error. |
||
| 80 | * |
||
| 81 | * @param bool $nonFatal |
||
| 82 | */ |
||
| 83 | 2 | public function taskError($nonFatal = true) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * @param string $serverName |
||
| 94 | * @param string $exceptionClass |
||
| 95 | * @param string $message |
||
| 96 | */ |
||
| 97 | public function taskException($serverName, $exceptionClass, $message) |
||
| 109 | } |
||
| 110 |