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 Mssql extends AbsractAdapter |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * @var int |
||
24 | */ |
||
25 | protected $port; |
||
26 | |||
27 | protected $schema = array ( 'public' ); |
||
28 | |||
29 | public function __construct ( AbstractAdapter $adapterConfig ) |
||
37 | |||
38 | /** |
||
39 | * @inheritDoc |
||
40 | */ |
||
41 | protected function convertTypeToSimple ( $str ) |
||
59 | |||
60 | protected function getHost(){ |
||
73 | |||
74 | /** |
||
75 | * @inheritDoc |
||
76 | * @return string |
||
77 | */ |
||
78 | public function getPDOString () |
||
86 | |||
87 | /** |
||
88 | * @inheritDoc |
||
89 | * @return string |
||
90 | */ |
||
91 | public function getPDOSocketString () |
||
96 | |||
97 | /** |
||
98 | * @inheritDoc |
||
99 | * @return string[] |
||
100 | */ |
||
101 | View Code Duplication | public function getListNameTable () |
|
129 | |||
130 | /** |
||
131 | * retorna multiplos arrays com dados da column em array |
||
132 | * |
||
133 | * @return array[] |
||
134 | */ |
||
135 | |||
136 | /** |
||
137 | * retorna multiplos arrays com dados da column em array |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | public function getListColumns () |
||
166 | |||
167 | /** |
||
168 | * retorna o numero total de tabelas |
||
169 | * |
||
170 | * @return int |
||
171 | */ |
||
172 | View Code Duplication | public function getTotalTables () |
|
194 | |||
195 | public function getSequence ( $table , $column , $schema = 0 ) |
||
210 | |||
211 | /** |
||
212 | * @return array |
||
213 | */ |
||
214 | public function getListConstrant () |
||
218 | |||
219 | /* |
||
220 | public function getListConstrant () |
||
221 | { |
||
222 | $sqlTables = ! empty( $this->tablesName ) |
||
223 | ? "AND tc.table_name IN ( $this->tablesName )" : ''; |
||
224 | $strSchema = implode ( "', '" , $this->schema ); |
||
225 | |||
226 | return $this->getPDO () |
||
227 | ->query ( |
||
228 | " |
||
229 | SELECT DISTINCT |
||
230 | tc.constraint_type, |
||
231 | tc.constraint_name, |
||
232 | tc.table_schema, |
||
233 | tc.table_name, |
||
234 | kcu.column_name, |
||
235 | ccu.table_schema AS foreign_schema, |
||
236 | ccu.table_name AS foreign_table, |
||
237 | ccu.column_name as foreign_column |
||
238 | FROM |
||
239 | {$this->database}.INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc |
||
240 | INNER JOIN {$this->database}.INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu |
||
241 | ON tc.constraint_name = kcu.constraint_name |
||
242 | AND tc.table_schema IN ('$strSchema') |
||
243 | AND tc.constraint_type IN ('FOREIGN KEY','PRIMARY KEY') |
||
244 | $sqlTables |
||
245 | INNER JOIN {$this->database}.information_schema.constraint_column_usage AS ccu |
||
246 | ON tc.constraint_name = ccu.constraint_name |
||
247 | ORDER by tc.table_schema;" |
||
248 | ) |
||
249 | ->fetchAll ( \PDO::FETCH_ASSOC ); |
||
250 | } |
||
251 | */ |
||
252 | |||
253 | } |
||
254 |
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.