| Conditions | 7 |
| Paths | 6 |
| Total Lines | 55 |
| Code Lines | 23 |
| 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 namespace Anomaly\Streams\Platform\Model; |
||
| 85 | protected function prepareValueData(FormBuilder $builder) |
||
| 86 | { |
||
| 87 | $form = $builder->getForm(); |
||
| 88 | |||
| 89 | $entry = $form->getEntry(); |
||
| 90 | $fields = $form->getFields(); |
||
| 91 | |||
| 92 | $allowed = $fields->allowed(); |
||
| 93 | $disabled = $fields->disabled(); |
||
| 94 | |||
| 95 | /* |
||
| 96 | * Set initial data from the |
||
| 97 | * entry, minus undesired data. |
||
| 98 | */ |
||
| 99 | $data = array_diff_key( |
||
| 100 | $entry->getUnguardedAttributes(), |
||
| 101 | array_merge( |
||
| 102 | ['id', 'created_at', 'created_by_id', 'updated_at', 'updated_by_id'], |
||
| 103 | array_flip($disabled->fieldSlugs()) |
||
| 104 | ) |
||
| 105 | ); |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Save default translation input. |
||
| 109 | * |
||
| 110 | * @var FieldType $field |
||
| 111 | */ |
||
| 112 | foreach ($allowed->notTranslatable() as $field) { |
||
| 113 | if (!$field->getLocale()) { |
||
| 114 | array_set($data, str_replace('__', '.', $field->getField()), $form->getValue($field->getInputName())); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | /* |
||
| 119 | * Loop through available translations |
||
| 120 | * and save translated input. |
||
| 121 | * |
||
| 122 | * @var FieldType $field |
||
| 123 | */ |
||
| 124 | if ($entry->getTranslationModelName()) { |
||
| 125 | foreach (config('streams::locales.enabled') as $locale) { |
||
| 126 | foreach ($allowed->translatable() as $field) { |
||
| 127 | if ($field->getLocale() == $locale) { |
||
| 128 | array_set( |
||
| 129 | $data, |
||
| 130 | $locale . '.' . $field->getField(), |
||
| 131 | $form->getValue($field->getInputName()) |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | return $data; |
||
| 139 | } |
||
| 140 | |||
| 161 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: