| Conditions | 40 |
| Paths | 13329 |
| Total Lines | 112 |
| Code Lines | 91 |
| 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 |
||
| 160 | private function loadField($table, $xml) { |
||
| 161 | $options = array( 'notnull' => false ); |
||
| 162 | foreach ($xml->children() as $child) { |
||
| 163 | /** |
||
| 164 | * @var \SimpleXMLElement $child |
||
| 165 | */ |
||
| 166 | switch ($child->getName()) { |
||
| 167 | case 'name': |
||
| 168 | $name = (string)$child; |
||
| 169 | $name = $this->platform->quoteIdentifier($name); |
||
| 170 | break; |
||
| 171 | case 'type': |
||
| 172 | $type = (string)$child; |
||
| 173 | switch ($type) { |
||
| 174 | case 'text': |
||
| 175 | $type = 'string'; |
||
| 176 | break; |
||
| 177 | case 'clob': |
||
| 178 | $type = 'text'; |
||
| 179 | break; |
||
| 180 | case 'timestamp': |
||
| 181 | $type = 'datetime'; |
||
| 182 | break; |
||
| 183 | case 'numeric': |
||
| 184 | $type = 'decimal'; |
||
| 185 | break; |
||
| 186 | } |
||
| 187 | break; |
||
| 188 | case 'length': |
||
| 189 | $length = (string)$child; |
||
| 190 | $options['length'] = $length; |
||
| 191 | break; |
||
| 192 | case 'unsigned': |
||
| 193 | $unsigned = $this->asBool($child); |
||
| 194 | $options['unsigned'] = $unsigned; |
||
| 195 | break; |
||
| 196 | case 'notnull': |
||
| 197 | $notnull = $this->asBool($child); |
||
| 198 | $options['notnull'] = $notnull; |
||
| 199 | break; |
||
| 200 | case 'autoincrement': |
||
| 201 | $autoincrement = $this->asBool($child); |
||
| 202 | $options['autoincrement'] = $autoincrement; |
||
| 203 | break; |
||
| 204 | case 'default': |
||
| 205 | $default = (string)$child; |
||
| 206 | $options['default'] = $default; |
||
| 207 | break; |
||
| 208 | case 'comments': |
||
| 209 | $comment = (string)$child; |
||
| 210 | $options['comment'] = $comment; |
||
| 211 | break; |
||
| 212 | case 'primary': |
||
| 213 | $primary = $this->asBool($child); |
||
| 214 | $options['primary'] = $primary; |
||
| 215 | break; |
||
| 216 | case 'precision': |
||
| 217 | $precision = (string)$child; |
||
| 218 | $options['precision'] = $precision; |
||
| 219 | break; |
||
| 220 | case 'scale': |
||
| 221 | $scale = (string)$child; |
||
| 222 | $options['scale'] = $scale; |
||
| 223 | break; |
||
| 224 | default: |
||
| 225 | throw new \DomainException('Unknown element: ' . $child->getName()); |
||
| 226 | |||
| 227 | } |
||
| 228 | } |
||
| 229 | if (isset($name) && isset($type)) { |
||
| 230 | if (isset($options['default']) && empty($options['default'])) { |
||
| 231 | if (empty($options['notnull']) || !$options['notnull']) { |
||
| 232 | unset($options['default']); |
||
| 233 | $options['notnull'] = false; |
||
| 234 | } else { |
||
| 235 | $options['default'] = ''; |
||
| 236 | } |
||
| 237 | if ($type == 'integer' || $type == 'decimal') { |
||
| 238 | $options['default'] = 0; |
||
| 239 | } elseif ($type == 'boolean') { |
||
| 240 | $options['default'] = false; |
||
| 241 | } |
||
| 242 | if (!empty($options['autoincrement']) && $options['autoincrement']) { |
||
| 243 | unset($options['default']); |
||
| 244 | } |
||
| 245 | } |
||
| 246 | if ($type === 'integer' && isset($options['default'])) { |
||
| 247 | $options['default'] = (int)$options['default']; |
||
| 248 | } |
||
| 249 | if ($type === 'integer' && isset($options['length'])) { |
||
| 250 | $length = $options['length']; |
||
| 251 | if ($length < 4) { |
||
| 252 | $type = 'smallint'; |
||
| 253 | } else if ($length > 4) { |
||
| 254 | $type = 'bigint'; |
||
| 255 | } |
||
| 256 | } |
||
| 257 | if ($type === 'boolean' && isset($options['default'])) { |
||
| 258 | $options['default'] = $this->asBool($options['default']); |
||
| 259 | } |
||
| 260 | if (!empty($options['autoincrement']) |
||
| 261 | && !empty($options['notnull']) |
||
| 262 | ) { |
||
| 263 | $options['primary'] = true; |
||
| 264 | } |
||
| 265 | |||
| 266 | $table->addColumn($name, $type, $options); |
||
| 267 | if (!empty($options['primary']) && $options['primary']) { |
||
| 268 | $table->setPrimaryKey(array($name)); |
||
| 269 | } |
||
| 270 | } |
||
| 271 | } |
||
| 272 | |||
| 352 |