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 |
||
| 11 | abstract class DbDumper |
||
| 12 | { |
||
| 13 | /** @var string */ |
||
| 14 | protected $dbName; |
||
| 15 | |||
| 16 | /** @var string */ |
||
| 17 | protected $userName; |
||
| 18 | |||
| 19 | /** @var string */ |
||
| 20 | protected $password; |
||
| 21 | |||
| 22 | /** @var string */ |
||
| 23 | protected $host = 'localhost'; |
||
| 24 | |||
| 25 | /** @var int */ |
||
| 26 | protected $port = 5432; |
||
| 27 | |||
| 28 | /** @var string */ |
||
| 29 | protected $socket = ''; |
||
| 30 | |||
| 31 | /** @var int */ |
||
| 32 | protected $timeout = 0; |
||
| 33 | |||
| 34 | /** @var string */ |
||
| 35 | protected $dumpBinaryPath = ''; |
||
| 36 | |||
| 37 | /** @var array */ |
||
| 38 | protected $includeTables = []; |
||
| 39 | |||
| 40 | /** @var array */ |
||
| 41 | protected $excludeTables = []; |
||
| 42 | |||
| 43 | /** @var array */ |
||
| 44 | protected $extraOptions = []; |
||
| 45 | |||
| 46 | /** @var string */ |
||
| 47 | protected $compressor = null; |
||
| 48 | |||
| 49 | public static function create() |
||
| 53 | |||
| 54 | public function getDbName(): string |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param string $dbName |
||
| 61 | * |
||
| 62 | * @return $this |
||
| 63 | */ |
||
| 64 | public function setDbName(string $dbName) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param string $userName |
||
| 73 | * |
||
| 74 | * @return $this |
||
| 75 | */ |
||
| 76 | public function setUserName(string $userName) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @param string $password |
||
| 85 | * |
||
| 86 | * @return $this |
||
| 87 | */ |
||
| 88 | public function setPassword(string $password) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param string $host |
||
| 97 | * |
||
| 98 | * @return $this |
||
| 99 | */ |
||
| 100 | public function setHost(string $host) |
||
| 106 | |||
| 107 | public function getHost(): string |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @param int $port |
||
| 114 | * |
||
| 115 | * @return $this |
||
| 116 | */ |
||
| 117 | public function setPort(int $port) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @param string $socket |
||
| 126 | * |
||
| 127 | * @return $this |
||
| 128 | */ |
||
| 129 | public function setSocket(string $socket) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @param int $timeout |
||
| 138 | * |
||
| 139 | * @return $this |
||
| 140 | */ |
||
| 141 | public function setTimeout(int $timeout) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param string $dumpBinaryPath |
||
| 150 | * |
||
| 151 | * @return $this |
||
| 152 | */ |
||
| 153 | public function setDumpBinaryPath(string $dumpBinaryPath) |
||
| 163 | |||
| 164 | public function enableCompression() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @param string $level |
||
| 171 | * |
||
| 172 | * @return $this |
||
| 173 | */ |
||
| 174 | public function GzipCompression(string $level = '9') |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param string $level |
||
| 185 | * |
||
| 186 | * @return $this |
||
| 187 | */ |
||
| 188 | public function Bzip2Compression(string $level = '9') |
||
| 196 | |||
| 197 | public function getCompressorExtension() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param string|array $includeTables |
||
| 204 | * |
||
| 205 | * @return $this |
||
| 206 | * |
||
| 207 | * @throws \Spatie\DbDumper\Exceptions\CannotSetParameter |
||
| 208 | */ |
||
| 209 | View Code Duplication | public function includeTables($includeTables) |
|
| 223 | |||
| 224 | /** |
||
| 225 | * @param string|array $excludeTables |
||
| 226 | * |
||
| 227 | * @return $this |
||
| 228 | * |
||
| 229 | * @throws \Spatie\DbDumper\Exceptions\CannotSetParameter |
||
| 230 | */ |
||
| 231 | View Code Duplication | public function excludeTables($excludeTables) |
|
| 245 | |||
| 246 | /** |
||
| 247 | * @param string $extraOption |
||
| 248 | * |
||
| 249 | * @return $this |
||
| 250 | */ |
||
| 251 | public function addExtraOption(string $extraOption) |
||
| 259 | |||
| 260 | abstract public function dumpToFile(string $dumpFile); |
||
| 261 | |||
| 262 | protected function checkIfDumpWasSuccessFul(Process $process, string $outputFile) |
||
| 276 | |||
| 277 | protected function echoToFile(string $command, string $dumpFile): string |
||
| 284 | } |
||
| 285 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..