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 $compression = 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 | /** |
||
165 | * @deprecated |
||
166 | * |
||
167 | * @return $this |
||
168 | */ |
||
169 | public function enableCompression() |
||
175 | |||
176 | /** |
||
177 | * @return $string |
||
178 | */ |
||
179 | public function getCompressionExtension() |
||
183 | |||
184 | /** |
||
185 | * Set the given compression. |
||
186 | * |
||
187 | * @param Compression $compression |
||
188 | * |
||
189 | * @return $this |
||
190 | */ |
||
191 | public function useCompression(Compression $compression) |
||
197 | |||
198 | /** |
||
199 | * @param string|array $includeTables |
||
200 | * |
||
201 | * @return $this |
||
202 | * |
||
203 | * @throws \Spatie\DbDumper\Exceptions\CannotSetParameter |
||
204 | */ |
||
205 | View Code Duplication | public function includeTables($includeTables) |
|
219 | |||
220 | /** |
||
221 | * @param string|array $excludeTables |
||
222 | * |
||
223 | * @return $this |
||
224 | * |
||
225 | * @throws \Spatie\DbDumper\Exceptions\CannotSetParameter |
||
226 | */ |
||
227 | View Code Duplication | public function excludeTables($excludeTables) |
|
241 | |||
242 | /** |
||
243 | * @param string $extraOption |
||
244 | * |
||
245 | * @return $this |
||
246 | */ |
||
247 | public function addExtraOption(string $extraOption) |
||
255 | |||
256 | abstract public function dumpToFile(string $dumpFile); |
||
257 | |||
258 | protected function checkIfDumpWasSuccessFul(Process $process, string $outputFile) |
||
272 | |||
273 | protected function echoToFile(string $command, string $dumpFile): string |
||
280 | } |
||
281 |
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..