| Conditions | 1 |
| Paths | 1 |
| Total Lines | 86 |
| 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' => 'title', |
||
| 20 | 'required' => true, |
||
| 21 | 'filters' => [['name' => 'StringTrim']], |
||
| 22 | 'validators' => [ |
||
| 23 | ['name' => 'NotEmpty'], |
||
| 24 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 100]], |
||
| 25 | ], |
||
| 26 | ] |
||
| 27 | ); |
||
| 28 | |||
| 29 | $inputFilter->add( |
||
| 30 | [ |
||
| 31 | 'name' => 'slug', |
||
| 32 | 'required' => true, |
||
| 33 | 'filters' => [['name' => 'StringTrim']], |
||
| 34 | 'validators' => [ |
||
| 35 | ['name' => 'NotEmpty'], |
||
| 36 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 100]], |
||
| 37 | ], |
||
| 38 | ] |
||
| 39 | ); |
||
| 40 | |||
| 41 | $inputFilter->add( |
||
| 42 | [ |
||
| 43 | 'name' => 'body', |
||
| 44 | 'required' => true, |
||
| 45 | 'filters' => [['name' => 'StringTrim']], |
||
| 46 | 'validators' => [ |
||
| 47 | ['name' => 'NotEmpty'], |
||
| 48 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 100000]], |
||
| 49 | ], |
||
| 50 | ] |
||
| 51 | ); |
||
| 52 | |||
| 53 | $inputFilter->add( |
||
| 54 | [ |
||
| 55 | 'name' => 'description', |
||
| 56 | 'required' => true, |
||
| 57 | 'filters' => [['name' => 'StringTrim']], |
||
| 58 | 'validators' => [ |
||
| 59 | ['name' => 'NotEmpty'], |
||
| 60 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 50000]], |
||
| 61 | ], |
||
| 62 | ] |
||
| 63 | ); |
||
| 64 | |||
| 65 | $inputFilter->add( |
||
| 66 | [ |
||
| 67 | 'name' => 'has_layout', |
||
| 68 | 'required' => false, |
||
| 69 | 'filters' => [['name' => 'Boolean']], |
||
| 70 | ] |
||
| 71 | ); |
||
| 72 | |||
| 73 | $inputFilter->add( |
||
| 74 | [ |
||
| 75 | 'name' => 'is_homepage', |
||
| 76 | 'required' => false, |
||
| 77 | 'filters' => [['name' => 'Boolean']], |
||
| 78 | ] |
||
| 79 | ); |
||
| 80 | |||
| 81 | $inputFilter->add( |
||
| 82 | [ |
||
| 83 | 'name' => 'is_active', |
||
| 84 | 'required' => false, |
||
| 85 | 'filters' => [['name' => 'Boolean']], |
||
| 86 | ] |
||
| 87 | ); |
||
| 88 | |||
| 89 | $inputFilter->add( |
||
| 90 | [ |
||
| 91 | 'name' => 'is_wysiwyg_editor', |
||
| 92 | 'required' => false, |
||
| 93 | 'filters' => [['name' => 'Boolean']], |
||
| 94 | ] |
||
| 95 | ); |
||
| 96 | |||
| 97 | return $inputFilter; |
||
| 98 | } |
||
| 99 | |||
| 105 |