| Conditions | 9 |
| Paths | 19 |
| Total Lines | 64 |
| Code Lines | 51 |
| 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 |
||
| 53 | protected function getModelsMetadataEntity() |
||
| 54 | { |
||
| 55 | $response = array(); |
||
| 56 | foreach ($this->getModelVersionInfo()->modelsForRequestedVersion() as $model_name => $model_classname) { |
||
| 57 | $model = $this->getModelVersionInfo()->loadModel($model_name); |
||
| 58 | $fields_json = array(); |
||
| 59 | foreach ($this->getModelVersionInfo()->fieldsOnModelInThisVersion($model) as $field_name => $field_obj) { |
||
| 60 | if ($this->getModelVersionInfo()->fieldIsIgnored($field_obj)) { |
||
| 61 | continue; |
||
| 62 | } |
||
| 63 | if ($field_obj instanceof EE_Boolean_Field) { |
||
| 64 | $datatype = 'Boolean'; |
||
| 65 | } elseif ($field_obj->get_wpdb_data_type() == '%d') { |
||
| 66 | $datatype = 'Number'; |
||
| 67 | } elseif ($field_name instanceof EE_Serialized_Text_Field) { |
||
| 68 | $datatype = 'Object'; |
||
| 69 | } else { |
||
| 70 | $datatype = 'String'; |
||
| 71 | } |
||
| 72 | $default_value = ModelDataTranslator::prepareFieldValueForJson( |
||
| 73 | $field_obj, |
||
| 74 | $field_obj->get_default_value(), |
||
| 75 | $this->getModelVersionInfo()->requestedVersion() |
||
| 76 | ); |
||
| 77 | $field_json = array( |
||
| 78 | 'name' => $field_name, |
||
| 79 | 'nicename' => $field_obj->get_nicename(), |
||
| 80 | 'has_rendered_format' => $this->getModelVersionInfo()->fieldHasRenderedFormat($field_obj), |
||
| 81 | 'has_pretty_format' => $this->getModelVersionInfo()->fieldHasPrettyFormat($field_obj), |
||
| 82 | 'type' => str_replace('EE_', '', get_class($field_obj)), |
||
| 83 | 'datatype' => $datatype, |
||
| 84 | 'nullable' => $field_obj->is_nullable(), |
||
| 85 | 'default' => $default_value, |
||
| 86 | 'table_alias' => $field_obj->get_table_alias(), |
||
| 87 | 'table_column' => $field_obj->get_table_column(), |
||
| 88 | ); |
||
| 89 | $fields_json[$field_json['name']] = $field_json; |
||
| 90 | } |
||
| 91 | $fields_json = array_merge( |
||
| 92 | $fields_json, |
||
| 93 | $this->getModelVersionInfo()->extraResourcePropertiesForModel($model) |
||
| 94 | ); |
||
| 95 | $response[$model_name]['fields'] = apply_filters( |
||
| 96 | 'FHEE__Meta__handle_request_models_meta__fields', |
||
| 97 | $fields_json, |
||
| 98 | $model |
||
| 99 | ); |
||
| 100 | $relations_json = array(); |
||
| 101 | foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
||
| 102 | $relation_json = array( |
||
| 103 | 'name' => $relation_name, |
||
| 104 | 'type' => str_replace('EE_', '', get_class($relation_obj)), |
||
| 105 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false, |
||
| 106 | ); |
||
| 107 | $relations_json[$relation_name] = $relation_json; |
||
| 108 | } |
||
| 109 | $response[$model_name]['relations'] = apply_filters( |
||
| 110 | 'FHEE__Meta__handle_request_models_meta__relations', |
||
| 111 | $relations_json, |
||
| 112 | $model |
||
| 113 | ); |
||
| 114 | } |
||
| 115 | return $response; |
||
| 116 | } |
||
| 117 | |||
| 153 |