| Conditions | 2 |
| Paths | 2 |
| Total Lines | 96 |
| 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 |
||
| 22 | public function getInputFilter() |
||
| 23 | { |
||
| 24 | if (!$this->inputFilter) { |
||
| 25 | $inputFilter = new InputFilter(); |
||
| 26 | |||
| 27 | $inputFilter->add( |
||
| 28 | [ |
||
| 29 | 'name' => 'first_name', |
||
| 30 | 'required' => true, |
||
| 31 | 'filters' => [['name' => 'StringTrim']], |
||
| 32 | 'validators' => [ |
||
| 33 | ['name' => 'NotEmpty'], |
||
| 34 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 255]], |
||
| 35 | ], |
||
| 36 | ] |
||
| 37 | ); |
||
| 38 | |||
| 39 | $inputFilter->add( |
||
| 40 | [ |
||
| 41 | 'name' => 'last_name', |
||
| 42 | 'required' => true, |
||
| 43 | 'filters' => [['name' => 'StringTrim']], |
||
| 44 | 'validators' => [ |
||
| 45 | ['name' => 'NotEmpty'], |
||
| 46 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 255]], |
||
| 47 | ], |
||
| 48 | ] |
||
| 49 | ); |
||
| 50 | |||
| 51 | $inputFilter->add( |
||
| 52 | [ |
||
| 53 | 'name' => 'email', |
||
| 54 | 'required' => true, |
||
| 55 | 'filters' => [['name' => 'StringTrim']], |
||
| 56 | 'validators' => [ |
||
| 57 | ['name' => 'NotEmpty'], |
||
| 58 | ['name' => 'EmailAddress'], |
||
| 59 | [ |
||
| 60 | 'name' => 'dbnorecordexists', |
||
| 61 | 'options' => ['adapter' => $this->adapter, 'table' => 'admin_users', 'field' => 'email'], |
||
| 62 | ], |
||
| 63 | ], |
||
| 64 | ] |
||
| 65 | ); |
||
| 66 | |||
| 67 | $inputFilter->add( |
||
| 68 | [ |
||
| 69 | 'name' => 'introduction', |
||
| 70 | 'required' => false, |
||
| 71 | 'filters' => [['name' => 'StringTrim']], |
||
| 72 | ] |
||
| 73 | ); |
||
| 74 | |||
| 75 | $inputFilter->add( |
||
| 76 | [ |
||
| 77 | 'name' => 'biography', |
||
| 78 | 'required' => false, |
||
| 79 | 'filters' => [['name' => 'StringTrim']], |
||
| 80 | ] |
||
| 81 | ); |
||
| 82 | |||
| 83 | $inputFilter->add( |
||
| 84 | [ |
||
| 85 | 'name' => 'password', |
||
| 86 | 'required' => true, |
||
| 87 | 'validators' => [ |
||
| 88 | ['name' => 'NotEmpty'], |
||
| 89 | ['name' => 'StringLength', 'options' => ['min' => 7, 'max' => 255]], |
||
| 90 | ], |
||
| 91 | ] |
||
| 92 | ); |
||
| 93 | |||
| 94 | $inputFilter->add( |
||
| 95 | [ |
||
| 96 | 'name' => 'confirm_password', |
||
| 97 | 'required' => true, |
||
| 98 | 'validators' => [ |
||
| 99 | ['name' => 'NotEmpty'], |
||
| 100 | ['name' => 'Identical', 'options' => ['token' => 'password']], |
||
| 101 | ], |
||
| 102 | ] |
||
| 103 | ); |
||
| 104 | |||
| 105 | $inputFilter->add( |
||
| 106 | [ |
||
| 107 | 'name' => 'status', |
||
| 108 | 'required' => true, |
||
| 109 | 'validators' => [['name' => 'NotEmpty'], ['name' => 'Digits']], |
||
| 110 | ] |
||
| 111 | ); |
||
| 112 | |||
| 113 | $this->inputFilter = $inputFilter; |
||
| 114 | } |
||
| 115 | |||
| 116 | return $this->inputFilter; |
||
| 117 | } |
||
| 118 | |||
| 124 |