| Conditions | 12 |
| Paths | 10 |
| Total Lines | 44 |
| Code Lines | 39 |
| 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 |
||
| 33 | public static function parseForm(CollectionDto $collectionDto) { |
||
| 34 | $form = new Form(false); |
||
| 35 | $form->addField(self::generateId()); |
||
| 36 | foreach($collectionDto->properties as $property) { |
||
| 37 | $values = null; |
||
| 38 | $data = []; |
||
| 39 | $url = null; |
||
| 40 | switch ($property->type) { |
||
| 41 | case NOSQLBase::NOSQL_TYPE_INTEGER: |
||
| 42 | case NOSQLBase::NOSQL_TYPE_DOUBLE: |
||
| 43 | case NOSQLBase::NOSQL_TYPE_LONG: |
||
| 44 | $type = Field::NUMBER_TYPE; |
||
| 45 | break; |
||
| 46 | case NOSQLBase::NOSQL_TYPE_BOOLEAN: |
||
| 47 | $type = Field::SWITCH_TYPE; |
||
| 48 | break; |
||
| 49 | case NOSQLBase::NOSQL_TYPE_ARRAY: |
||
| 50 | $type = Field::COMBO_TYPE; |
||
| 51 | break; |
||
| 52 | case NOSQLBase::NOSQL_TYPE_DATE: |
||
| 53 | $type = Field::TIMESTAMP; |
||
| 54 | break; |
||
| 55 | case NOSQLBase::NOSQL_TYPE_OBJECT: |
||
| 56 | $type = Field::TEXTAREA_TYPE; |
||
| 57 | break; |
||
| 58 | case NOSQLBase::NOSQL_TYPE_ENUM: |
||
| 59 | $type = Field::COMBO_TYPE; |
||
| 60 | $enumValues = explode('|', $property->enum); |
||
|
|
|||
| 61 | foreach($enumValues as $value) { |
||
| 62 | $data[] = [ |
||
| 63 | $property->name => $value, |
||
| 64 | 'Label' => t($value), |
||
| 65 | ]; |
||
| 66 | }; |
||
| 67 | break; |
||
| 68 | default: |
||
| 69 | $type = Field::TEXT_TYPE; |
||
| 70 | break; |
||
| 71 | } |
||
| 72 | $field = new Field($property->name, $property->description ?: $property->name, $type, $values, $data, $url, $property->required); |
||
| 73 | $field->pk = false; |
||
| 74 | $form->addField($field); |
||
| 75 | } |
||
| 76 | return $form; |
||
| 77 | } |
||
| 78 | } |