Conditions | 16 |
Paths | 3073 |
Total Lines | 66 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 2 | Features | 1 |
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 |
||
25 | public static function createTable(Blueprint $table): string |
||
26 | { |
||
27 | $query = "CREATE TABLE `".$table->getTable()."`"; |
||
28 | |||
29 | // go through columns |
||
30 | $query .= " ("; |
||
31 | foreach ($table->getColumns() as $key => $Column) |
||
32 | { |
||
33 | $query .= "`".$Column->name."` "; |
||
34 | |||
35 | $query .= $Column->type; |
||
36 | |||
37 | if(isset($Column->length)) { |
||
38 | $query .= "(".$Column->length; |
||
39 | } |
||
40 | |||
41 | if(isset($Column->scale) && isset($Column->length)) { |
||
42 | $query .= ", ".$Column->scale.")"; |
||
43 | } else { |
||
44 | if(isset($Column->length)) { |
||
45 | $query .= ")"; |
||
46 | } |
||
47 | } |
||
48 | |||
49 | if($Column->isUnsigned) { |
||
50 | $query .= " UNSIGNED"; |
||
51 | } |
||
52 | |||
53 | if($Column->notNull) { |
||
54 | $query .= " NOT NULL"; |
||
55 | } |
||
56 | |||
57 | if($Column->isAutoIncrement) { |
||
58 | $query .= " AUTO_INCREMENT"; |
||
59 | } |
||
60 | |||
61 | if($Column->primaryKey) { |
||
62 | $query .= " PRIMARY KEY"; |
||
63 | } |
||
64 | |||
65 | if($Column->foreignKey) { |
||
66 | $query .= " FOREIGN KEY"; |
||
67 | } |
||
68 | |||
69 | if($Column->unique) { |
||
70 | $query .= " UNIQUE"; |
||
71 | } |
||
72 | |||
73 | if($Column->default != null) { |
||
74 | $default = $Column->default; |
||
75 | if (is_string($default)) { |
||
76 | if (str($default)->startsWith("%")) |
||
77 | $default = str($default)->explode("%")->last(); |
||
78 | else |
||
79 | $default = "'".$default."'"; |
||
80 | } |
||
81 | |||
82 | $query .= " DEFAULT ".$default; |
||
83 | } |
||
84 | |||
85 | if(count($table->getColumns())-1 != $key) |
||
86 | $query .= ", "; |
||
87 | } |
||
88 | $query .= ");"; |
||
89 | |||
90 | return $query; |
||
91 | } |
||
102 |