| Conditions | 9 | 
| Paths | 1 | 
| Total Lines | 84 | 
| Code Lines | 46 | 
| 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 | ||
| 51 | public function __construct(GeocoderInterface $geocoder, FeatureRepository $feature) | ||
| 52 |     { | ||
| 53 | parent::__construct(); | ||
| 54 | |||
| 55 | $this->geocoder = $geocoder; | ||
| 56 | $this->feature = $feature; | ||
| 57 | |||
| 58 |         $this->addEventListener(FormEvents::POST_SUBMIT, function (JobForm $form) { | ||
| 59 | // call macro and flush collection items | ||
| 60 | $this->data->tags->flush(); | ||
| 61 | $this->data->locations->flush(); | ||
|  | |||
| 62 | $this->data->features->flush(); | ||
| 63 | |||
| 64 |             foreach ($form->get('tags')->getChildrenValues() as $tag) { | ||
| 65 | $pivot = $this->data->tags()->newPivot(['priority' => $tag['priority']]); | ||
| 66 |                 $model = (new Tag($tag))->setRelation('pivot', $pivot); | ||
| 67 | |||
| 68 | $this->data->tags->add($model); | ||
| 69 | } | ||
| 70 | |||
| 71 |             foreach ($form->get('features')->getChildrenValues() as $feature) { | ||
| 72 | $checked = (int) $feature['checked']; | ||
| 73 | |||
| 74 | $pivot = $this->data->features()->newPivot([ | ||
| 75 | 'checked' => $checked, | ||
| 76 | 'value' => $checked ? ($feature['value'] ?? null) : null | ||
| 77 | ]); | ||
| 78 | |||
| 79 |                 $model = $this->feature->find($feature['id'])->setRelation('pivot', $pivot); | ||
| 80 | |||
| 81 | $this->data->features->add($model); | ||
| 82 | } | ||
| 83 | |||
| 84 |             $cities = (new City())->grab($form->get('city')->getValue()); | ||
| 85 | |||
| 86 |             foreach ($cities as $city) { | ||
| 87 | $this->data->locations->add(new Job\Location($this->geocode($city))); | ||
| 88 | } | ||
| 89 | |||
| 90 |             $this->data->country()->associate((new Country())->find($form->get('country_id')->getValue())); | ||
| 1 ignored issue–
                            show | |||
| 91 | }); | ||
| 92 | |||
| 93 |         $this->addEventListener(FormEvents::PRE_RENDER, function (JobForm $form) { | ||
| 94 | $session = $form->getRequest()->session(); | ||
| 95 | |||
| 96 |             if ($session->hasOldInput('tags')) { | ||
| 97 | $assoc = []; | ||
| 98 | |||
| 99 |                 foreach ($form->get('tags')->getChildrenValues() as $tag) { | ||
| 100 | $assoc[] = [ | ||
| 101 | 'name' => $tag['name'], | ||
| 102 | 'pivot' => [ | ||
| 103 | 'priority' => $tag['priority'] | ||
| 104 | ] | ||
| 105 | ]; | ||
| 106 | } | ||
| 107 | |||
| 108 |                 $form->get('tags')->setValue($assoc); | ||
| 109 | } | ||
| 110 | |||
| 111 |             if ($session->hasOldInput('features')) { | ||
| 112 | $assoc = []; | ||
| 113 | |||
| 114 |                 foreach ($form->get('features')->getChildrenValues() as $feature) { | ||
| 115 | $assoc[] = [ | ||
| 116 | 'id' => $feature['id'], | ||
| 117 | 'name' => $feature['name'], | ||
| 118 | 'default' => $feature['default'], | ||
| 119 | 'pivot' => [ | ||
| 120 | 'checked' => (int) $feature['checked'], | ||
| 121 | 'value' => $feature['value'] ?? '' | ||
| 122 | ] | ||
| 123 | ]; | ||
| 124 | } | ||
| 125 | |||
| 126 |                 $form->get('features')->setValue($assoc); | ||
| 127 | } | ||
| 128 | |||
| 129 | // tags as json (for vue.js) | ||
| 130 |             $form->get('tags')->setValue(collect($form->get('tags')->getChildrenValues())->toJson()); | ||
| 131 | // features as json (for vue.js) | ||
| 132 |             $form->get('features')->setValue(collect($form->get('features')->getChildrenValues())->toJson()); | ||
| 133 | }); | ||
| 134 | } | ||
| 135 | |||
| 349 | 
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.