Complex classes like AbstractAdapter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractAdapter, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | abstract class AbstractAdapter |
||
17 | { |
||
18 | |||
19 | protected $arrConfig = array ( |
||
20 | ############################# DATABASE |
||
21 | //Driver do banco de dados |
||
22 | 'driver' => null , |
||
23 | //Nome do banco de dados |
||
24 | 'database' => null , |
||
25 | //Host do banco |
||
26 | 'host' => 'localhost' , |
||
27 | //Port do banco |
||
28 | 'port' => '' , |
||
29 | //usuario do banco |
||
30 | 'username' => null , |
||
31 | //senha do banco |
||
32 | 'password' => null , |
||
33 | // lista de schemas do banco de dados |
||
34 | 'schema' => array () , |
||
35 | 'version' => '' , |
||
36 | 'socket' => null , |
||
37 | |||
38 | ########################### DOCS |
||
39 | // autor que gerou o script |
||
40 | 'author' => "Pedro" , |
||
41 | 'license' => "New BSD License" , |
||
42 | 'copyright' => "ORM Generator - Pedro151" , |
||
43 | 'link' => 'https://github.com/pedro151/orm-generator' , |
||
44 | 'version' => '' , |
||
45 | // data que foi gerado o script |
||
46 | 'last_modify' => null , |
||
47 | |||
48 | ########################## Ambiente/Arquivos |
||
49 | |||
50 | // Nome do framework para o adapter |
||
51 | 'framework' => null , |
||
52 | // namespace das classes |
||
53 | 'namespace' => "" , |
||
54 | // caminho onde os arquivos devem ser criados |
||
55 | 'path' => 'models' , |
||
56 | // flag para gerar pasta com o nome do driver do banco de dados |
||
57 | 'folder-database' => 0 , |
||
58 | // string com o nome da pastar personalizada |
||
59 | 'folder-name' => '' , |
||
60 | |||
61 | 'clean-trash' => false, |
||
62 | |||
63 | ############################## Comandos adicionais |
||
64 | //flag para mostrar o status da execução ao termino do processo |
||
65 | 'status' => false , |
||
66 | // flags para criar todas as tabelas ou nao |
||
67 | 'tables' => array () , |
||
68 | // lista de Classes opcionais pre-definidas para serem criadas |
||
69 | 'optional-classes'=> array (), |
||
70 | //Lista de tabelas a serem ignoradas |
||
71 | 'ignoreTable' => array () , |
||
72 | ); |
||
73 | |||
74 | /** |
||
75 | * @var string[] um array com todos os campos obrigatorios |
||
76 | */ |
||
77 | protected $attRequered = array ( |
||
78 | 'driver' => true , |
||
79 | 'database' => true , |
||
80 | 'host' => true , |
||
81 | 'username' => true , |
||
82 | 'path' => true |
||
83 | ); |
||
84 | |||
85 | protected $arrFunc = array (); |
||
86 | |||
87 | private $framworkFiles = array (); |
||
88 | |||
89 | public $reservedWord = array (); |
||
90 | |||
91 | private static $dataTypesDefault = array ( |
||
92 | 'int' => 'int' , |
||
93 | 'float' => 'float' , |
||
94 | 'string' => 'string' , |
||
95 | 'text' => 'string' , |
||
96 | 'date' => 'date' , |
||
97 | 'datetime' => 'datetime' , |
||
98 | 'timestamp' => 'timestamp' , |
||
99 | 'boolean' => 'boolean' |
||
100 | ); |
||
101 | |||
102 | protected $dataTypes = array (); |
||
103 | |||
104 | const SEPARETOR = ""; |
||
105 | |||
106 | /** |
||
107 | * verifica se todos valores obrigatorios tem valor |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | protected function checkConfig () |
||
120 | |||
121 | /** |
||
122 | * retorna os parametros da configuração do framework |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | abstract protected function getParams (); |
||
127 | |||
128 | /** |
||
129 | * Popula as config do generater com as configuraçoes do framework |
||
130 | * |
||
131 | * @return mixed |
||
132 | */ |
||
133 | abstract protected function parseFrameworkConfig (); |
||
134 | |||
135 | /** |
||
136 | * Cria Instancias dos arquivos que devem ser gerados |
||
137 | * |
||
138 | * @return \Classes\AdapterMakerFile\AbstractAdapter[] |
||
139 | */ |
||
140 | abstract public function getMakeFileInstances (); |
||
141 | |||
142 | abstract protected function init (); |
||
143 | |||
144 | /** |
||
145 | * retorna a base do Namespace |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | protected function getBaseNamespace () |
||
156 | |||
157 | /** |
||
158 | * @param \Classes\Db\DbTable|\Classes\Db\Constrant $table |
||
159 | * |
||
160 | * @return mixed |
||
161 | */ |
||
162 | |||
163 | public function createClassNamespace ( $table ) |
||
191 | |||
192 | public function __construct ( $array ) |
||
213 | |||
214 | /** |
||
215 | * Set os arquivos de configuracao do framework |
||
216 | * |
||
217 | * @param $array |
||
218 | */ |
||
219 | public function setFrameworkFiles ( $array ) |
||
231 | |||
232 | protected function isValidFrameworkFiles () |
||
262 | |||
263 | protected function getFrameworkIni () |
||
267 | |||
268 | protected function getEnvironment () |
||
272 | |||
273 | /** |
||
274 | * Popula as variaveis de acordo com o arquivo de configuração do seu framework |
||
275 | */ |
||
276 | protected function isValid () |
||
280 | |||
281 | private function setParams ( $array ) |
||
288 | |||
289 | /** |
||
290 | * @return string |
||
291 | */ |
||
292 | public function getDatabase () |
||
296 | |||
297 | /** |
||
298 | * @return bool |
||
299 | */ |
||
300 | public function hasSchemas () |
||
304 | |||
305 | /** |
||
306 | * @return string[] |
||
307 | */ |
||
308 | public function getSchemas () |
||
317 | |||
318 | public function setSchema ( $schema ) |
||
322 | |||
323 | /** |
||
324 | * @return string |
||
325 | */ |
||
326 | public function getHost () |
||
330 | |||
331 | /** |
||
332 | * @return int |
||
333 | */ |
||
334 | public function getPort () |
||
338 | |||
339 | /** |
||
340 | * @return boolean |
||
341 | */ |
||
342 | public function hasPort () |
||
346 | |||
347 | /** |
||
348 | * @return boolean |
||
349 | */ |
||
350 | public function isCleanTrash(){ |
||
353 | |||
354 | /** |
||
355 | * @return string |
||
356 | */ |
||
357 | public function getSocket () |
||
361 | |||
362 | /** |
||
363 | * @return string |
||
364 | */ |
||
365 | public function getUser () |
||
369 | |||
370 | /** |
||
371 | * @return string |
||
372 | */ |
||
373 | public function getPassword () |
||
377 | |||
378 | /** |
||
379 | * @param string $schema |
||
380 | * |
||
381 | * @return string |
||
382 | */ |
||
383 | public function replaceReservedWord ( $palavra ) |
||
392 | |||
393 | /** |
||
394 | * @return bool |
||
395 | */ |
||
396 | public function isStatusEnabled () |
||
400 | |||
401 | public function validTableNames () |
||
409 | |||
410 | /** |
||
411 | * @return bool |
||
412 | */ |
||
413 | public function hasTablesName (){ |
||
416 | |||
417 | /** |
||
418 | * @return string[] |
||
419 | */ |
||
420 | public function getTablesName () |
||
429 | |||
430 | /** |
||
431 | * @return string |
||
432 | */ |
||
433 | public function getListTablesName(){ |
||
437 | |||
438 | /** |
||
439 | * @return bool |
||
440 | */ |
||
441 | public function hasOptionalClasses (){ |
||
444 | |||
445 | /** |
||
446 | * @return string[] |
||
447 | */ |
||
448 | public function getOptionalClasses () |
||
457 | |||
458 | /** |
||
459 | * @param $str |
||
460 | * |
||
461 | * @return string |
||
462 | */ |
||
463 | public function __get ( $str ) |
||
486 | |||
487 | /** |
||
488 | * @param string $type |
||
489 | * |
||
490 | * @return string |
||
491 | */ |
||
492 | public static function convertTypeToPHP ( $type ) |
||
496 | |||
497 | /** |
||
498 | * @param string $type |
||
499 | * |
||
500 | * @return string |
||
501 | */ |
||
502 | public function convertTypeToTypeFramework ( $type ) |
||
506 | } |
||
507 |
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.