| Conditions | 2 |
| Paths | 2 |
| Total Lines | 77 |
| Code Lines | 47 |
| 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 |
||
| 87 | public function getInputFilter() |
||
| 88 | { |
||
| 89 | if (!$this->inputFilter) { |
||
| 90 | $inputFilter = new InputFilter(); |
||
| 91 | $factory = new InputFactory(); |
||
| 92 | |||
| 93 | $inputFilter->add($factory->createInput([ |
||
| 94 | 'name' => 'id', |
||
| 95 | 'required' => true, |
||
| 96 | 'filters' => [ |
||
| 97 | ['name' => 'Int'], |
||
| 98 | ], |
||
| 99 | ])); |
||
| 100 | |||
| 101 | $inputFilter->add($factory->createInput([ |
||
| 102 | 'name' => 'thread', |
||
| 103 | 'required' => true, |
||
| 104 | 'filters' => [ |
||
| 105 | ['name' => 'Alnum'], |
||
| 106 | ], |
||
| 107 | ])); |
||
| 108 | |||
| 109 | $inputFilter->add($factory->createInput([ |
||
| 110 | 'name' => 'author', |
||
| 111 | 'required' => true, |
||
| 112 | 'filters' => [ |
||
| 113 | ['name' => 'StripTags'], |
||
| 114 | ['name' => 'StringTrim'], |
||
| 115 | ], |
||
| 116 | 'validators' => [ |
||
| 117 | [ |
||
| 118 | 'name' => 'StringLength', |
||
| 119 | 'options' => [ |
||
| 120 | 'encoding' => 'UTF-8', |
||
| 121 | 'min' => 1, |
||
| 122 | 'max' => 150, |
||
| 123 | ], |
||
| 124 | ], |
||
| 125 | ], |
||
| 126 | ])); |
||
| 127 | |||
| 128 | $inputFilter->add($factory->createInput([ |
||
| 129 | 'name' => 'contact', |
||
| 130 | 'required' => true, |
||
| 131 | 'filters' => [ |
||
| 132 | ['name' => 'StripTags'], |
||
| 133 | ['name' => 'StringTrim'], |
||
| 134 | ], |
||
| 135 | 'validators' => [ |
||
| 136 | [ |
||
| 137 | 'name' => 'EmailAddress', |
||
| 138 | ], |
||
| 139 | [ |
||
| 140 | 'name' => 'StringLength', |
||
| 141 | 'options' => [ |
||
| 142 | 'encoding' => 'UTF-8', |
||
| 143 | 'min' => 1, |
||
| 144 | 'max' => 200, |
||
| 145 | ], |
||
| 146 | ], |
||
| 147 | ], |
||
| 148 | ])); |
||
| 149 | |||
| 150 | $inputFilter->add($factory->createInput([ |
||
| 151 | 'name' => 'content', |
||
| 152 | 'required' => true, |
||
| 153 | 'filters' => [ |
||
| 154 | ['name' => 'StripTags'], |
||
| 155 | ['name' => 'StringTrim'], |
||
| 156 | ], |
||
| 157 | ])); |
||
| 158 | |||
| 159 | $this->inputFilter = $inputFilter; |
||
| 160 | } |
||
| 161 | |||
| 162 | return $this->inputFilter; |
||
| 163 | } |
||
| 164 | } |
||
| 165 |