| Conditions | 19 |
| Paths | 1323 |
| Total Lines | 98 |
| Code Lines | 48 |
| 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 |
||
| 54 | private function tableInformations($table) |
||
| 55 | { |
||
| 56 | $foreignKeys = $this->schema->getConnection()->getForeignKeys($table); |
||
| 57 | |||
| 58 | $columns = $this->schema->getConnection()->showColumnsFrom($table); |
||
| 59 | |||
| 60 | $status = $this->schema->getConnection()->getTableStatus($table); |
||
| 61 | |||
| 62 | $indexes = $this->schema->getConnection()->showIndexes($table); |
||
| 63 | $multipleIndexes = $this->getMultipleIndex($indexes); |
||
| 64 | |||
| 65 | $list = []; |
||
| 66 | |||
| 67 | foreach ($columns as $key=>$data){ |
||
| 68 | |||
| 69 | $field = $data['Field']; |
||
| 70 | $list[] = '$wizard->name(\''.$field.'\')'; |
||
| 71 | $list[] = '->'.$this->getColumnTransformers($data['Type']).''; |
||
| 72 | |||
| 73 | //default block |
||
| 74 | if(!is_null($data['Default'])){ |
||
| 75 | $default = $data['Default']; |
||
| 76 | $list[] = '->default(\''.$default.'\')'; |
||
| 77 | } |
||
| 78 | |||
| 79 | $getIndex = $this->getIndexInformation($indexes,$data['Field']); |
||
| 80 | |||
| 81 | //unique block |
||
| 82 | if($getIndex['Non_unique']=='0' && $getIndex['Key_name']!=='PRIMARY'){ |
||
| 83 | $indexName = $getIndex['Key_name']; |
||
| 84 | $list[] = '->unique(\''.$indexName.'\')'; |
||
| 85 | } |
||
| 86 | |||
| 87 | //index block |
||
| 88 | if($getIndex['Non_unique']=='1' && $getIndex['Key_name']!=='PRIMARY'){ |
||
| 89 | $columnName = $getIndex['Column_name']; |
||
|
|
|||
| 90 | $indexName = $getIndex['Key_name']; |
||
| 91 | |||
| 92 | if(count($multipleIndexes[$indexName])==1){ |
||
| 93 | $list[] = '->index(\''.$indexName.'\')'; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | //comment block |
||
| 98 | if(strlen($data['Comment'])>0){ |
||
| 99 | $comment = $data['Comment']; |
||
| 100 | $list[] = '->comment(\''.$comment.'\')'; |
||
| 101 | } |
||
| 102 | |||
| 103 | //auto increment block |
||
| 104 | if($data['Extra']=='auto_increment'){ |
||
| 105 | $list[] = '->auto_increment()'; |
||
| 106 | } |
||
| 107 | |||
| 108 | $list[] = '; |
||
| 109 | '; |
||
| 110 | } |
||
| 111 | |||
| 112 | //table collation |
||
| 113 | $charset = $this->schema->getConnection()->getCharsetForCollation(''.$status['Collation'].''); |
||
| 114 | $list[] = '$wizard->table()->collation(\''.$charset.'\'); |
||
| 115 | '; |
||
| 116 | |||
| 117 | //table indexes |
||
| 118 | foreach ($multipleIndexes as $indexName=>$values) { |
||
| 119 | if(count($values)>1){ |
||
| 120 | $values = '\''.implode('\',\'',$values).'\''; |
||
| 121 | $list[] = ' $wizard->table()->indexes(\''.$indexName.'\',['.$values.']); |
||
| 122 | '; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | if(count($foreignKeys)){ |
||
| 127 | |||
| 128 | $constraintName = $foreignKeys['CONSTRAINT_NAME']; |
||
| 129 | $key = $foreignKeys['COLUMN_NAME']; |
||
| 130 | $referenceTable = $foreignKeys['REFERENCED_TABLE_NAME']; |
||
| 131 | $referenceColumn = $foreignKeys['REFERENCED_COLUMN_NAME']; |
||
| 132 | |||
| 133 | if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
||
| 134 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\'); |
||
| 135 | '; |
||
| 136 | } |
||
| 137 | |||
| 138 | if($foreignKeys['UPDATE_RULE']!=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
||
| 139 | $rule = $foreignKeys['UPDATE_RULE']; |
||
| 140 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onUpdate()->'.strtolower($rule).'(); |
||
| 141 | '; |
||
| 142 | } |
||
| 143 | |||
| 144 | if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']!=='RESTRICT'){ |
||
| 145 | $rule = $foreignKeys['DELETE_RULE']; |
||
| 146 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onDelete()->'.strtolower($rule).'(); |
||
| 147 | '; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | return implode('',$list); |
||
| 152 | } |
||
| 216 | } |