Conditions | 23 |
Paths | 3084 |
Total Lines | 83 |
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 |
||
128 | public function convert($database = null) |
||
129 | { |
||
130 | if (!is_null($database)) { |
||
131 | $this->database = $database; |
||
132 | $this->customDb = true; |
||
133 | } |
||
134 | |||
135 | $tables = $this->getTables(); |
||
136 | |||
137 | // Loop over the tables |
||
138 | foreach ($tables as $key => $value) { |
||
139 | // Do not export the ignored tables |
||
140 | if (in_array($value['table_name'], static::$ignore)) { |
||
141 | continue; |
||
142 | } |
||
143 | |||
144 | $down = "Schema::dropIfExists('{$value['table_name']}');"; |
||
145 | $up = "Schema::create('{$value['table_name']}', function(Blueprint $"."table) {\n"; |
||
146 | |||
147 | $tableDescribes = $this->getTableDescribes($value['table_name']); |
||
148 | // Loop over the tables fields |
||
149 | foreach ($tableDescribes as $values) { |
||
150 | $para = strpos($values->Type, '('); |
||
151 | $type = $para > -1 ? substr($values->Type, 0, $para) : $values->Type; |
||
152 | $nullable = 'NO' == $values->Nullable ? '' : '->nullable()'; |
||
153 | $default = empty($values->Default) || 'NULL' == $values->Default ? '' : "->default({$values->Default})"; |
||
154 | $default = 'CURRENT_TIMESTAMP' == $values->Default || 'current_timestamp()' == $values->Default ? '->useCurrent()' : $default; |
||
155 | $unsigned = false === strpos($values->Type, 'unsigned') ? '' : '->unsigned()'; |
||
156 | $this->hasDefaults($type, $values); |
||
157 | $this->methodName = $this->columnType($type); |
||
158 | if ('PRI' == $values->Key) { |
||
159 | $this->primaryKey = '->primary()'; |
||
160 | if ($methodName = $this->columnType($values->Data_Type, 'primaryKeys') && 'auto_increment' == $values->Extra) { |
||
161 | $this->primaryKey = '->autoIncrement()'; |
||
162 | } |
||
163 | } |
||
164 | |||
165 | $up .= ' $'."table->{$this->methodName}('{$values->Field}'{$this->defaultLength}){$this->primaryKey}{$nullable}{$default}{$unsigned};\n"; |
||
166 | $this->unsetData(); |
||
167 | }//end foreach |
||
168 | |||
169 | $tableIndexes = (array) $this->getTableIndexes($value['table_name']); |
||
170 | if (!is_null($tableIndexes) && count($tableIndexes)) { |
||
171 | foreach ($tableIndexes as $index) { |
||
172 | if (Str::endsWith(@$index['Key_name'], '_index')) { |
||
173 | $up .= ' $'."table->index('".$index['Column_name']."');\n"; |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 | |||
178 | $up .= " });\n\n"; |
||
179 | $Constraint = $ConstraintDown = ''; |
||
180 | /* |
||
181 | * @var array |
||
182 | */ |
||
183 | $tableConstraints = $this->getTableConstraints($value['table_name']); |
||
184 | if (!is_null($tableConstraints) && $tableConstraints->count()) { |
||
185 | $Constraint = $ConstraintDown = " |
||
186 | Schema::table('{$value['table_name']}', function(Blueprint $"."table) {\n"; |
||
187 | $tables = []; |
||
188 | foreach ($tableConstraints as $foreign) { |
||
189 | if (!in_array($foreign->Field, $tables)) { |
||
190 | $field = "{$foreign->Table}_{$foreign->Field}_foreign"; |
||
191 | $ConstraintDown .= ' $'."table->dropForeign('".$field."');\n"; |
||
192 | $Constraint .= ' $'."table->foreign('".$foreign->Field."')->references('".$foreign->References."')->on('".$foreign->ON."')->onDelete('".$foreign->onDelete."');\n"; |
||
193 | $tables[$foreign->Field] = $foreign->Field; |
||
194 | } |
||
195 | } |
||
196 | |||
197 | $Constraint .= " });\n\n"; |
||
198 | $ConstraintDown .= " });\n\n"; |
||
199 | } |
||
200 | |||
201 | $this->schema[$value['table_name']] = [ |
||
202 | 'up' => $up, |
||
203 | 'constraint' => $Constraint, |
||
204 | 'constraint_down' => $ConstraintDown, |
||
205 | 'down' => $down, |
||
206 | ]; |
||
207 | }//end foreach |
||
208 | |||
209 | return $this; |
||
210 | } |
||
211 | |||
316 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.