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 |
||
19 | class Pgsql extends AbsractAdapter |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * @var int |
||
24 | */ |
||
25 | protected $port = 5432; |
||
26 | |||
27 | /** |
||
28 | * @type array|\string[] |
||
29 | */ |
||
30 | protected $schema = array ( 'public' ); |
||
31 | |||
32 | protected $dataTypesToSimple = array ( |
||
33 | /* Numeric Types */ |
||
34 | 'smallint' => 'int', |
||
35 | 'integer' => 'int', |
||
36 | 'serial' => 'int', |
||
37 | 'bigint' => 'float', |
||
38 | 'decimal' => 'float', |
||
39 | 'numeric' => 'float', |
||
40 | 'real' => 'float', |
||
41 | 'double precision' => 'float', |
||
42 | 'bigserial' => 'float', |
||
43 | /* Monetary Types */ |
||
44 | 'money' => 'float', |
||
45 | /* Binary Data Types */ |
||
46 | 'bytea' => 'int', |
||
47 | /* Character Types */ |
||
48 | 'character varyin' => 'string', |
||
49 | 'varchar' => 'string', |
||
50 | 'character' => 'string', |
||
51 | 'char' => 'string', |
||
52 | 'text' => 'text', |
||
53 | /* Date/Time Types */ |
||
54 | 'datetime' => 'datetime', |
||
55 | 'timestamp without time zone' => 'timestamp', |
||
56 | 'date' => 'date', |
||
57 | /* Boolean Type */ |
||
58 | 'boolean' => 'boolean' |
||
59 | ); |
||
60 | |||
61 | public function __construct ( AbstractAdapter $adapterConfig ) |
||
69 | |||
70 | /** |
||
71 | * Retorna um Array com nome das tabelas |
||
72 | * |
||
73 | * @param void $schema |
||
74 | * |
||
75 | * @return string[] |
||
76 | */ |
||
77 | View Code Duplication | public function getListNameTable () |
|
103 | |||
104 | /** |
||
105 | * retorna multiplos arrays com dados da column em array |
||
106 | * |
||
107 | * @return array |
||
108 | */ |
||
109 | View Code Duplication | public function getListColumns () |
|
133 | |||
134 | View Code Duplication | public function getListConstrant () |
|
164 | |||
165 | /** |
||
166 | * Retorna o Nome da Sequence da tabela |
||
167 | * |
||
168 | * @param $table |
||
169 | * @param $column |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | public function getSequence ( $table, $column, $schema = 0 ) |
||
217 | |||
218 | /** |
||
219 | * @inheritDoc |
||
220 | * @return string |
||
221 | */ |
||
222 | public function getPDOString () |
||
232 | |||
233 | /** |
||
234 | * @inheritDoc |
||
235 | * @return string |
||
236 | */ |
||
237 | public function getPDOSocketString () |
||
246 | |||
247 | /** |
||
248 | * retorna o numero total de tabelas |
||
249 | * |
||
250 | * @return int |
||
251 | */ |
||
252 | View Code Duplication | public function getTotalTables () |
|
272 | } |
||
273 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.