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 | protected $socketDirectory = ''; |
||
12 | |||
13 | /** |
||
14 | * PostgreSql constructor. |
||
15 | */ |
||
16 | public function __construct() |
||
20 | |||
21 | /** |
||
22 | * @return string |
||
23 | */ |
||
24 | public function getDbName() |
||
28 | |||
29 | /** |
||
30 | * @param string $dbName |
||
31 | * |
||
32 | * @return \Spatie\DbDumper\Databases\PostgreSql |
||
33 | */ |
||
34 | public function setDbName($dbName) |
||
40 | |||
41 | /** |
||
42 | * @param string $userName |
||
43 | * |
||
44 | * @return \Spatie\DbDumper\Databases\PostgreSql |
||
45 | */ |
||
46 | public function setUserName($userName) |
||
52 | |||
53 | /** |
||
54 | * @param string $password |
||
55 | * |
||
56 | * @return \Spatie\DbDumper\Databases\PostgreSql |
||
57 | */ |
||
58 | public function setPassword($password) |
||
64 | |||
65 | /** |
||
66 | * @param string $host |
||
67 | * |
||
68 | * @return \Spatie\DbDumper\Databases\PostgreSql |
||
69 | */ |
||
70 | public function setHost($host) |
||
76 | |||
77 | /** |
||
78 | * @param int $port |
||
79 | * |
||
80 | * @return \Spatie\DbDumper\Databases\PostgreSql |
||
81 | */ |
||
82 | public function setPort($port) |
||
88 | |||
89 | /** |
||
90 | * @param string $socketDirectory |
||
91 | * |
||
92 | * @return \Spatie\DbDumper\Databases\PostgreSql |
||
93 | */ |
||
94 | public function setSocketDirectory($socketDirectory) |
||
100 | |||
101 | /** |
||
102 | * Dump the contents of the database to the given file. |
||
103 | * |
||
104 | * @param string $dumpFile |
||
105 | * |
||
106 | * @throws \Spatie\DbDumper\Exceptions\CannotStartDump |
||
107 | * @throws \Spatie\DbDumper\Exceptions\DumpFailed |
||
108 | */ |
||
109 | public function dumpToFile($dumpFile) |
||
121 | |||
122 | /** |
||
123 | * Get the command that should be performed to dump the database. |
||
124 | * |
||
125 | * @param string $dumpFile |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | public function getDumpCommand($dumpFile) |
||
149 | |||
150 | View Code Duplication | protected function guardAgainstIncompleteCredentials() |
|
158 | } |
||
159 |
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.