| Conditions | 1 |
| Paths | 1 |
| Total Lines | 66 |
| 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 |
||
| 13 | public function getInputFilter() |
||
| 14 | { |
||
| 15 | $inputFilter = new InputFilter(); |
||
| 16 | |||
| 17 | $inputFilter->add( |
||
| 18 | [ |
||
| 19 | 'name' => 'full_name', |
||
| 20 | 'required' => true, |
||
| 21 | 'filters' => [['name' => 'StringTrim'], ['name' => 'StripTags'], ['name' => 'StripNewlines']], |
||
| 22 | 'validators' => [ |
||
| 23 | ['name' => 'NotEmpty'], |
||
| 24 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 1000]], |
||
| 25 | ], |
||
| 26 | ] |
||
| 27 | ); |
||
| 28 | |||
| 29 | $inputFilter->add( |
||
| 30 | [ |
||
| 31 | 'name' => 'email', |
||
| 32 | 'required' => true, |
||
| 33 | 'filters' => [['name' => 'StringTrim'], ['name' => 'StripTags'], ['name' => 'StripNewlines']], |
||
| 34 | 'validators' => [ |
||
| 35 | ['name' => 'NotEmpty'], |
||
| 36 | ['name' => 'EmailAddress'], |
||
| 37 | ], |
||
| 38 | ] |
||
| 39 | ); |
||
| 40 | |||
| 41 | $inputFilter->add( |
||
| 42 | [ |
||
| 43 | 'name' => 'phone', |
||
| 44 | 'required' => true, |
||
| 45 | 'filters' => [['name' => 'StringTrim'], ['name' => 'StripTags'], ['name' => 'StripNewlines']], |
||
| 46 | 'validators' => [ |
||
| 47 | ['name' => 'NotEmpty'], |
||
| 48 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 30]], |
||
| 49 | ], |
||
| 50 | ] |
||
| 51 | ); |
||
| 52 | |||
| 53 | $inputFilter->add( |
||
| 54 | [ |
||
| 55 | 'name' => 'url', |
||
| 56 | 'required' => true, |
||
| 57 | 'filters' => [['name' => 'StringTrim'], ['name' => 'StripTags'], ['name' => 'StripNewlines']], |
||
| 58 | 'validators' => [ |
||
| 59 | ['name' => 'NotEmpty'], |
||
| 60 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 1000]], |
||
| 61 | ], |
||
| 62 | ] |
||
| 63 | ); |
||
| 64 | |||
| 65 | $inputFilter->add( |
||
| 66 | [ |
||
| 67 | 'name' => 'cover_letter', |
||
| 68 | 'required' => true, |
||
| 69 | 'filters' => [['name' => 'StringTrim'], ['name' => 'StripTags'], ['name' => 'StripNewlines']], |
||
| 70 | 'validators' => [ |
||
| 71 | ['name' => 'NotEmpty'], |
||
| 72 | ['name' => 'StringLength', 'options' => ['min' => 10, 'max' => 10000]], |
||
| 73 | ], |
||
| 74 | ] |
||
| 75 | ); |
||
| 76 | |||
| 77 | return $inputFilter; |
||
| 78 | } |
||
| 79 | |||
| 84 | } |