| Conditions | 19 |
| Paths | 1323 |
| Total Lines | 101 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 |
||
| 104 | private function tableInformations($table) |
||
| 105 | { |
||
| 106 | $foreignKeys = $this->schema->getConnection()->getForeignKeys($table); |
||
| 107 | |||
| 108 | $columns = $this->schema->getConnection()->showColumnsFrom($table); |
||
| 109 | |||
| 110 | $status = $this->schema->getConnection()->getTableStatus($table); |
||
| 111 | |||
| 112 | $indexes = $this->schema->getConnection()->showIndexes($table); |
||
| 113 | $multipleIndexes = $this->getMultipleIndex($indexes); |
||
| 114 | |||
| 115 | |||
| 116 | $list = []; |
||
| 117 | |||
| 118 | foreach ($columns as $key=>$data){ |
||
| 119 | |||
| 120 | $data['Type'] = rtrim(str_replace('unsigned','',$data['Type'])); |
||
| 121 | |||
| 122 | $field = $data['Field']; |
||
| 123 | $list[] = '$wizard->name(\''.$field.'\')'; |
||
| 124 | $list[] = '->'.$this->getColumnTransformers($data['Type']).''; |
||
| 125 | |||
| 126 | //default block |
||
| 127 | if(!is_null($data['Default'])){ |
||
| 128 | $default = $data['Default']; |
||
| 129 | $list[] = '->default(\''.$default.'\')'; |
||
| 130 | } |
||
| 131 | |||
| 132 | $getIndex = $this->getIndexInformation($indexes,$data['Field']); |
||
| 133 | |||
| 134 | //unique block |
||
| 135 | if($getIndex['Non_unique']=='0' && $getIndex['Key_name']!=='PRIMARY'){ |
||
| 136 | $indexName = $getIndex['Key_name']; |
||
| 137 | $list[] = '->unique(\''.$indexName.'\')'; |
||
| 138 | } |
||
| 139 | |||
| 140 | //index block |
||
| 141 | if($getIndex['Non_unique']=='1' && $getIndex['Key_name']!=='PRIMARY'){ |
||
| 142 | $columnName = $getIndex['Column_name']; |
||
| 143 | $indexName = $getIndex['Key_name']; |
||
| 144 | |||
| 145 | if(count($multipleIndexes[$indexName])==1){ |
||
| 146 | $list[] = '->index(\''.$indexName.'\')'; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | //comment block |
||
| 151 | if(strlen($data['Comment'])>0){ |
||
| 152 | $comment = $data['Comment']; |
||
| 153 | $list[] = '->comment(\''.$comment.'\')'; |
||
| 154 | } |
||
| 155 | |||
| 156 | //auto increment block |
||
| 157 | if($data['Extra']=='auto_increment'){ |
||
| 158 | $list[] = '->auto_increment()'; |
||
| 159 | } |
||
| 160 | |||
| 161 | $list[] = '; |
||
| 162 | '; |
||
| 163 | } |
||
| 164 | |||
| 165 | //table collation |
||
| 166 | $charset = $this->schema->getConnection()->getCharsetForCollation(''.$status['Collation'].''); |
||
| 167 | $list[] = '$wizard->table()->collation(\''.$charset.'\'); |
||
| 168 | '; |
||
| 169 | |||
| 170 | //table indexes |
||
| 171 | foreach ($multipleIndexes as $indexName=>$values) { |
||
| 172 | if(count($values)>1){ |
||
| 173 | $values = '\''.implode('\',\'',$values).'\''; |
||
| 174 | $list[] = ' $wizard->table()->indexes(\''.$indexName.'\',['.$values.']); |
||
| 175 | '; |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | if(count($foreignKeys)){ |
||
| 180 | |||
| 181 | $constraintName = $foreignKeys['CONSTRAINT_NAME']; |
||
| 182 | $key = $foreignKeys['COLUMN_NAME']; |
||
| 183 | $referenceTable = $foreignKeys['REFERENCED_TABLE_NAME']; |
||
| 184 | $referenceColumn = $foreignKeys['REFERENCED_COLUMN_NAME']; |
||
| 185 | |||
| 186 | if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
||
| 187 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\'); |
||
| 188 | '; |
||
| 189 | } |
||
| 190 | |||
| 191 | if($foreignKeys['UPDATE_RULE']!=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
||
| 192 | $rule = $foreignKeys['UPDATE_RULE']; |
||
| 193 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onUpdate()->'.strtolower($rule).'(); |
||
| 194 | '; |
||
| 195 | } |
||
| 196 | |||
| 197 | if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']!=='RESTRICT'){ |
||
| 198 | $rule = $foreignKeys['DELETE_RULE']; |
||
| 199 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onDelete()->'.strtolower($rule).'(); |
||
| 200 | '; |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | return implode('',$list); |
||
| 205 | } |
||
| 317 | } |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.