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 TailCommand extends Command |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * The console command signature. |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | protected $signature = 'tail |
||
| 17 | {connection? : The name of remote.} |
||
| 18 | {--path= : The fully qualified path to the log file.} |
||
| 19 | {--lines=20 : The number of lines to tail.} |
||
| 20 | '; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The console command description. |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $description = '[+] Tail a log file'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Execute the console command. |
||
| 31 | */ |
||
| 32 | 5 | public function handle() |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Get the path to the Laravel log file. |
||
| 67 | * |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | 1 | View Code Duplication | protected function getLocalPath() |
| 85 | |||
| 86 | /** |
||
| 87 | * Tail a local log file for the application. |
||
| 88 | * |
||
| 89 | * @param string $path |
||
| 90 | * |
||
| 91 | * @return string |
||
| 92 | */ |
||
| 93 | 1 | View Code Duplication | protected function tailLocalLogs($path) |
| 103 | |||
| 104 | /** |
||
| 105 | * Get the path to the Laravel log file. |
||
| 106 | * |
||
| 107 | * @param string $connection |
||
| 108 | * |
||
| 109 | * @return string |
||
| 110 | */ |
||
| 111 | 1 | protected function getRemotePath($connection) |
|
| 115 | |||
| 116 | /** |
||
| 117 | * Get the path to the Laravel log file. |
||
| 118 | * |
||
| 119 | * @return string |
||
| 120 | */ |
||
| 121 | 1 | View Code Duplication | protected function getRemotePathFromStorage() |
| 136 | |||
| 137 | /** |
||
| 138 | * Get the path to the Laravel install root. |
||
| 139 | * |
||
| 140 | * @param string $connection |
||
| 141 | * |
||
| 142 | * @return string |
||
| 143 | */ |
||
| 144 | 1 | protected function getRoot($connection) |
|
| 148 | |||
| 149 | /** |
||
| 150 | * Tail a remote log file at the given path and connection. |
||
| 151 | * |
||
| 152 | * @param string $path |
||
| 153 | * @param string $connection |
||
| 154 | */ |
||
| 155 | 1 | View Code Duplication | protected function tailRemoteLogs($path, $connection) |
| 165 | |||
| 166 | /** |
||
| 167 | * Get a connection to the remote server. |
||
| 168 | * |
||
| 169 | * @param string $connection |
||
| 170 | * |
||
| 171 | * @return \Illuminate\Remote\Connection |
||
| 172 | */ |
||
| 173 | 1 | protected function getRemote($connection) |
|
| 177 | } |
||
| 178 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.