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