Conditions | 15 |
Paths | 120 |
Total Lines | 49 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | 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 |
||
46 | public function makeField(string $tableName, array $field, Column $column): array |
||
47 | { |
||
48 | switch (app(MigrationsGeneratorSetting::class)->getPlatform()) { |
||
49 | // It could be pgsql enum |
||
50 | case Platform::POSTGRESQL: |
||
51 | if (($pgSQLEnum = $this->getPgSQLEnumValue($tableName, $column->getName())) !== '') { |
||
52 | $field['type'] = ColumnType::ENUM; |
||
53 | $field['args'][] = $pgSQLEnum; |
||
54 | } |
||
55 | break; |
||
56 | // It could be sqlsrv text |
||
57 | case Platform::SQLSERVER: |
||
58 | $colDef = $this->sqlSrvRepository->getColumnDefinition($tableName, $column->getName()); |
||
59 | if ($colDef->getType() === self::SQLSRV_TEXT_TYPE && |
||
60 | $colDef->getLength() === self::SQLSRV_TEXT_LENGTH) { |
||
61 | $field['type'] = ColumnType::TEXT; |
||
62 | } |
||
63 | break; |
||
64 | default: |
||
65 | } |
||
66 | |||
67 | // Continue if type is `string` |
||
68 | if ($field['type'] === ColumnType::STRING) { |
||
69 | if ($field['field'] === ColumnName::REMEMBER_TOKEN && $column->getLength() === 100 && !$column->getFixed()) { |
||
70 | $field['type'] = ColumnType::REMEMBER_TOKEN; |
||
71 | $field['field'] = null; |
||
72 | $field['args'] = []; |
||
73 | } else { |
||
74 | if ($column->getFixed()) { |
||
75 | $field['type'] = ColumnType::CHAR; |
||
76 | } |
||
77 | |||
78 | if ($column->getLength() && $column->getLength() !== Builder::$defaultStringLength) { |
||
|
|||
79 | $field['args'][] = $column->getLength(); |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | |||
84 | $charset = $this->charsetModifier->generate($tableName, $column); |
||
85 | if ($charset !== '') { |
||
86 | $field['decorators'][] = $charset; |
||
87 | } |
||
88 | |||
89 | $collation = $this->collationModifier->generate($tableName, $column); |
||
90 | if ($collation !== '') { |
||
91 | $field['decorators'][] = $collation; |
||
92 | } |
||
93 | |||
94 | return $field; |
||
95 | } |
||
109 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: