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 PostgreSql extends DbDumper |
||
10 | { |
||
11 | /** @var bool */ |
||
12 | protected $useInserts = false; |
||
13 | |||
14 | /** @var bool */ |
||
15 | protected $createTables = true; |
||
16 | |||
17 | public function __construct() |
||
21 | |||
22 | /** |
||
23 | * @return $this |
||
24 | */ |
||
25 | public function useInserts() |
||
31 | |||
32 | /** |
||
33 | * Dump the contents of the database to the given file. |
||
34 | * |
||
35 | * @param string $dumpFile |
||
36 | * |
||
37 | * @throws \Spatie\DbDumper\Exceptions\CannotStartDump |
||
38 | * @throws \Spatie\DbDumper\Exceptions\DumpFailed |
||
39 | */ |
||
40 | View Code Duplication | public function dumpToFile(string $dumpFile) |
|
58 | |||
59 | /** |
||
60 | * Get the command that should be performed to dump the database. |
||
61 | * |
||
62 | * @param string $dumpFile |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | public function getDumpCommand(string $dumpFile): string |
||
99 | |||
100 | public function getContentsOfCredentialsFile(): string |
||
112 | |||
113 | protected function guardAgainstIncompleteCredentials() |
||
121 | |||
122 | protected function getEnvironmentVariablesForDumpCommand(string $temporaryCredentialsFile): array |
||
129 | |||
130 | /** |
||
131 | * @return $this |
||
132 | */ |
||
133 | public function doNotCreateTables() |
||
139 | } |
||
140 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.