| Conditions | 1 |
| Paths | 1 |
| Total Lines | 134 |
| Code Lines | 95 |
| 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 |
||
| 73 | public function buildForm() |
||
| 74 | { |
||
| 75 | $countryList = Country::pluck('name', 'id')->toArray(); |
||
| 76 | |||
| 77 | $this |
||
| 78 | ->setAttr(['class' => 'submit-form', 'v-cloak' => 'v-cloak']) |
||
| 79 | ->setUrl(route('job.submit')) |
||
| 80 | ->add('id', 'hidden') |
||
| 81 | ->add('slug', 'hidden') |
||
| 82 | ->add('firm_id', 'hidden') |
||
| 83 | ->add('title', 'text', [ |
||
| 84 | 'rules' => 'min:2|max:60', |
||
| 85 | 'label' => 'Tytuł oferty', |
||
| 86 | 'required' => true, |
||
| 87 | 'help' => 'Pozostało <strong>${ charCounter(\'job.title\', 60) }</strong> znaków', |
||
| 88 | 'attr' => [ |
||
| 89 | 'placeholder' => 'Np. Senior Java Developer', |
||
| 90 | 'maxlength' => 60, |
||
| 91 | 'v-model' => 'job.title' |
||
| 92 | ], |
||
| 93 | 'row_attr' => [ |
||
| 94 | 'class' => 'form-group form-group-border' |
||
| 95 | ] |
||
| 96 | ]) |
||
| 97 | ->add('country_id', 'select', [ |
||
| 98 | 'rules' => 'required|integer', |
||
| 99 | 'choices' => $countryList |
||
| 100 | ]) |
||
| 101 | ->add('city', 'text', [ |
||
| 102 | 'rules' => 'string|city', |
||
| 103 | 'attr' => [ |
||
| 104 | 'placeholder' => 'Np. Wrocław, Warszawa' |
||
| 105 | ] |
||
| 106 | ]) |
||
| 107 | ->add('is_remote', 'checkbox', [ |
||
| 108 | 'label' => 'Możliwa praca zdalna w zakresie', |
||
| 109 | 'rules' => 'bool', |
||
| 110 | 'attr' => [ |
||
| 111 | 'id' => 'remote' |
||
| 112 | ], |
||
| 113 | 'label_attr' => [ |
||
| 114 | 'for' => 'remote' |
||
| 115 | ] |
||
| 116 | |||
| 117 | ]) |
||
| 118 | ->add('remote_range', 'select', [ |
||
| 119 | 'rules' => 'integer|min:10|max:100', |
||
| 120 | 'choices' => Job::getRemoteRangeList(), |
||
| 121 | 'attr' => [ |
||
| 122 | 'placeholder' => '--', |
||
| 123 | 'class' => 'input-sm input-inline', |
||
| 124 | 'style' => 'width: 100px' |
||
| 125 | ] |
||
| 126 | ]) |
||
| 127 | ->add('salary_from', 'text', [ |
||
| 128 | 'rules' => 'integer', |
||
| 129 | 'help' => 'Podanie tych informacji nie jest obowiązkowe, ale dzięki temu Twoja oferta zainteresuje więcej osób. Obiecujemy!', |
||
| 130 | 'attr' => [ |
||
| 131 | 'class' => 'input-inline' |
||
| 132 | ] |
||
| 133 | ]) |
||
| 134 | ->add('salary_to', 'text', [ |
||
| 135 | 'rules' => 'integer', |
||
| 136 | 'attr' => [ |
||
| 137 | 'class' => 'input-inline' |
||
| 138 | ] |
||
| 139 | ]) |
||
| 140 | ->add('currency_id', 'select', [ |
||
| 141 | 'rules' => 'required|integer', |
||
| 142 | 'choices' => Currency::pluck('name', 'id')->toArray(), |
||
| 143 | 'attr' => [ |
||
| 144 | 'class' => 'input-inline' |
||
| 145 | ] |
||
| 146 | ]) |
||
| 147 | ->add('rate_id', 'select', [ |
||
| 148 | 'rules' => 'required|integer', |
||
| 149 | 'choices' => Job::getRatesList(), |
||
| 150 | 'attr' => [ |
||
| 151 | 'class' => 'input-inline' |
||
| 152 | ] |
||
| 153 | ]) |
||
| 154 | ->add('employment_id', 'select', [ |
||
| 155 | 'rules' => 'required|integer', |
||
| 156 | 'choices' => Job::getEmploymentList(), |
||
| 157 | 'attr' => [ |
||
| 158 | 'class' => 'input-inline' |
||
| 159 | ] |
||
| 160 | ]) |
||
| 161 | ->add('deadline', 'text', [ |
||
| 162 | 'label' => 'Data ważnosci oferty', |
||
| 163 | 'rules' => 'integer|min:1|max:365', |
||
| 164 | 'help' => 'Oferta będzie widoczna na stronie do dnia <strong>${ deadlineDate }</strong>', |
||
| 165 | 'attr' => [ |
||
| 166 | 'class' => 'input-inline', |
||
| 167 | 'v-model' => 'job.deadline' |
||
| 168 | ] |
||
| 169 | ]) |
||
| 170 | ->add('tags', 'collection', [ |
||
| 171 | 'child_attr' => [ |
||
| 172 | 'type' => 'child_form', |
||
| 173 | 'class' => TagsForm::class |
||
| 174 | ] |
||
| 175 | ]) |
||
| 176 | ->add('description', 'textarea', [ |
||
| 177 | 'label' => 'Opis oferty', |
||
| 178 | 'help' => 'Miejsce na szczegółowy opis oferty. Pole to jednak nie jest wymagane.', |
||
| 179 | 'style' => 'height: 140px' |
||
| 180 | ]) |
||
| 181 | ->add('enable_apply', 'choice', [ |
||
| 182 | 'multiple' => false, |
||
| 183 | 'choices' => [ |
||
| 184 | |||
| 185 | true => 'Zezwól na wysyłanie CV poprzez serwis 4programmers.net', |
||
| 186 | false => '...lub podaj informacje w jaki sposób kandydaci mogą aplikować na to stanowisko', |
||
| 187 | ] |
||
| 188 | ]) |
||
| 189 | ->add('recruitment', 'textarea', [ |
||
| 190 | 'rules' => 'required_if:enable_apply,0|string', |
||
| 191 | 'style' => 'height: 40px' |
||
| 192 | ]) |
||
| 193 | ->add('email', 'email', [ |
||
| 194 | 'rules' => 'sometimes|required|email', |
||
| 195 | 'help' => 'Podaj adres e-mail na jaki wyślemy Ci informacje o kandydatach. Adres e-mail nie będzie widoczny dla osób postronnych.' |
||
| 196 | ]) |
||
| 197 | |||
| 198 | ->add('submit', 'submit', [ |
||
| 199 | 'label' => 'Zapisz', |
||
| 200 | 'attr' => [ |
||
| 201 | 'data-submit-state' => 'Wysyłanie...' |
||
| 202 | ] |
||
| 203 | ]); |
||
| 204 | |||
| 205 | $this->setupDefaultValues(); |
||
| 206 | } |
||
| 207 | |||
| 254 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: