| Conditions | 19 |
| Paths | 1323 |
| Total Lines | 101 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 62 | private function tableInformations($table) |
||
| 63 | { |
||
| 64 | $foreignKeys = $this->schema->getConnection()->getForeignKeys($table); |
||
| 65 | |||
| 66 | $columns = $this->schema->getConnection()->showColumnsFrom($table); |
||
| 67 | |||
| 68 | $status = $this->schema->getConnection()->getTableStatus($table); |
||
| 69 | |||
| 70 | $indexes = $this->schema->getConnection()->showIndexes($table); |
||
| 71 | $multipleIndexes = $this->getMultipleIndex($indexes); |
||
| 72 | |||
| 73 | |||
| 74 | $list = []; |
||
| 75 | |||
| 76 | foreach ($columns as $key=>$data){ |
||
| 77 | |||
| 78 | $data['Type'] = rtrim(str_replace('unsigned','',$data['Type'])); |
||
| 79 | |||
| 80 | $field = $data['Field']; |
||
| 81 | $list[] = '$wizard->name(\''.$field.'\')'; |
||
| 82 | $list[] = '->'.$this->getColumnTransformers($data['Type']).''; |
||
| 83 | |||
| 84 | //default block |
||
| 85 | if(!is_null($data['Default'])){ |
||
| 86 | $default = $data['Default']; |
||
| 87 | $list[] = '->default(\''.$default.'\')'; |
||
| 88 | } |
||
| 89 | |||
| 90 | $getIndex = $this->getIndexInformation($indexes,$data['Field']); |
||
| 91 | |||
| 92 | //unique block |
||
| 93 | if($getIndex['Non_unique']=='0' && $getIndex['Key_name']!=='PRIMARY'){ |
||
| 94 | $indexName = $getIndex['Key_name']; |
||
| 95 | $list[] = '->unique(\''.$indexName.'\')'; |
||
| 96 | } |
||
| 97 | |||
| 98 | //index block |
||
| 99 | if($getIndex['Non_unique']=='1' && $getIndex['Key_name']!=='PRIMARY'){ |
||
| 100 | $columnName = $getIndex['Column_name']; |
||
|
|
|||
| 101 | $indexName = $getIndex['Key_name']; |
||
| 102 | |||
| 103 | if(count($multipleIndexes[$indexName])==1){ |
||
| 104 | $list[] = '->index(\''.$indexName.'\')'; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | //comment block |
||
| 109 | if(strlen($data['Comment'])>0){ |
||
| 110 | $comment = $data['Comment']; |
||
| 111 | $list[] = '->comment(\''.$comment.'\')'; |
||
| 112 | } |
||
| 113 | |||
| 114 | //auto increment block |
||
| 115 | if($data['Extra']=='auto_increment'){ |
||
| 116 | $list[] = '->auto_increment()'; |
||
| 117 | } |
||
| 118 | |||
| 119 | $list[] = '; |
||
| 120 | '; |
||
| 121 | } |
||
| 122 | |||
| 123 | //table collation |
||
| 124 | $charset = $this->schema->getConnection()->getCharsetForCollation(''.$status['Collation'].''); |
||
| 125 | $list[] = '$wizard->table()->collation(\''.$charset.'\'); |
||
| 126 | '; |
||
| 127 | |||
| 128 | //table indexes |
||
| 129 | foreach ($multipleIndexes as $indexName=>$values) { |
||
| 130 | if(count($values)>1){ |
||
| 131 | $values = '\''.implode('\',\'',$values).'\''; |
||
| 132 | $list[] = ' $wizard->table()->indexes(\''.$indexName.'\',['.$values.']); |
||
| 133 | '; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | if(count($foreignKeys)){ |
||
| 138 | |||
| 139 | $constraintName = $foreignKeys['CONSTRAINT_NAME']; |
||
| 140 | $key = $foreignKeys['COLUMN_NAME']; |
||
| 141 | $referenceTable = $foreignKeys['REFERENCED_TABLE_NAME']; |
||
| 142 | $referenceColumn = $foreignKeys['REFERENCED_COLUMN_NAME']; |
||
| 143 | |||
| 144 | if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
||
| 145 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\'); |
||
| 146 | '; |
||
| 147 | } |
||
| 148 | |||
| 149 | if($foreignKeys['UPDATE_RULE']!=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
||
| 150 | $rule = $foreignKeys['UPDATE_RULE']; |
||
| 151 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onUpdate()->'.strtolower($rule).'(); |
||
| 152 | '; |
||
| 153 | } |
||
| 154 | |||
| 155 | if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']!=='RESTRICT'){ |
||
| 156 | $rule = $foreignKeys['DELETE_RULE']; |
||
| 157 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onDelete()->'.strtolower($rule).'(); |
||
| 158 | '; |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | return implode('',$list); |
||
| 163 | } |
||
| 251 | } |