| Conditions | 8 | 
| Paths | 36 | 
| Total Lines | 78 | 
| Code Lines | 32 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 7 | ||
| Bugs | 1 | 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 namespace Anomaly\PreferencesModule\Preference\Form;  | 
            ||
| 40 | public function handle(PreferenceFormBuilder $builder, PreferenceRepositoryInterface $preferences)  | 
            ||
| 41 |     { | 
            ||
| 42 | $namespace = $builder->getEntry() . '::';  | 
            ||
| 43 | |||
| 44 | /**  | 
            ||
| 45 | * Get the fields from the config system. Sections are  | 
            ||
| 46 | * optionally defined the same way.  | 
            ||
| 47 | */  | 
            ||
| 48 |         if (!$fields = $this->config->get($namespace . 'preferences/preferences')) { | 
            ||
| 49 | $fields = $fields = $this->config->get($namespace . 'preferences', []);  | 
            ||
| 50 | }  | 
            ||
| 51 | |||
| 52 |         if ($sections = $this->config->get($namespace . 'preferences/sections')) { | 
            ||
| 53 | $builder->setSections($sections);  | 
            ||
| 54 | }  | 
            ||
| 55 | |||
| 56 | /**  | 
            ||
| 57 | * Finish each field.  | 
            ||
| 58 | */  | 
            ||
| 59 |         foreach ($fields as $slug => &$field) { | 
            ||
| 60 | |||
| 61 | /**  | 
            ||
| 62 | * Force an array. This is done later  | 
            ||
| 63 | * too in normalization but we need it now  | 
            ||
| 64 | * because we are normalizing / guessing our  | 
            ||
| 65 | * own parameters somewhat.  | 
            ||
| 66 | */  | 
            ||
| 67 |             if (is_string($field)) { | 
            ||
| 68 | $field = [  | 
            ||
| 69 | 'type' => $field  | 
            ||
| 70 | ];  | 
            ||
| 71 | }  | 
            ||
| 72 | |||
| 73 | // Make sure we have a config property.  | 
            ||
| 74 | $field['config'] = array_get($field, 'config', []);  | 
            ||
| 75 | |||
| 76 | // Default the label.  | 
            ||
| 77 | $field['label'] = array_get(  | 
            ||
| 78 | $field,  | 
            ||
| 79 | 'label',  | 
            ||
| 80 | $namespace . 'preference.' . $slug . '.label'  | 
            ||
| 81 | );  | 
            ||
| 82 | |||
| 83 | // Default the placeholder.  | 
            ||
| 84 | $field['config']['placeholder'] = array_get(  | 
            ||
| 85 | $field['config'],  | 
            ||
| 86 | 'placeholder',  | 
            ||
| 87 | $namespace . 'preference.' . $slug . '.placeholder'  | 
            ||
| 88 | );  | 
            ||
| 89 | |||
| 90 | // Default the instructions.  | 
            ||
| 91 | $field['instructions'] = array_get(  | 
            ||
| 92 | $field,  | 
            ||
| 93 | 'instructions',  | 
            ||
| 94 | $namespace . 'preference.' . $slug . '.instructions'  | 
            ||
| 95 | );  | 
            ||
| 96 | |||
| 97 | // Get the value defaulting to the default value.  | 
            ||
| 98 | |||
| 99 |             if ($preference = $preferences->get($namespace . $slug)) { | 
            ||
| 100 | $field['value'] = $preference->getValue();  | 
            ||
| 101 |             } else { | 
            ||
| 102 | $field['value'] = array_get($field['config'], 'default_value');  | 
            ||
| 103 | }  | 
            ||
| 104 | |||
| 105 | /**  | 
            ||
| 106 | * Disable the field if it  | 
            ||
| 107 | * has a set env value.  | 
            ||
| 108 | */  | 
            ||
| 109 |             if (isset($field['env']) && ($value = env($field['env'])) !== null) { | 
            ||
| 110 | $field['disabled'] = true;  | 
            ||
| 111 | $field['value'] = $value;  | 
            ||
| 112 | $field['warning'] = 'module::message.env_locked';  | 
            ||
| 113 | }  | 
            ||
| 114 | }  | 
            ||
| 115 | |||
| 116 | $builder->setFields($fields);  | 
            ||
| 117 | }  | 
            ||
| 118 | }  | 
            ||
| 119 |