| Conditions | 2 |
| Paths | 2 |
| Total Lines | 90 |
| 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 |
||
| 23 | public function getInputFilter() |
||
| 24 | { |
||
| 25 | if (!$this->inputFilter) { |
||
| 26 | $inputFilter = new InputFilter(); |
||
| 27 | |||
| 28 | $inputFilter->add( |
||
| 29 | [ |
||
| 30 | 'name' => 'title', |
||
| 31 | 'required' => true, |
||
| 32 | 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], |
||
| 33 | 'validators' => [ |
||
| 34 | ['name' => 'NotEmpty'], |
||
| 35 | ['name' => 'StringLength', 'options' => ['max' => '255']], |
||
| 36 | ], |
||
| 37 | ] |
||
| 38 | ); |
||
| 39 | |||
| 40 | $inputFilter->add( |
||
| 41 | [ |
||
| 42 | 'name' => 'href', |
||
| 43 | 'required' => false, |
||
| 44 | 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], |
||
| 45 | ] |
||
| 46 | ); |
||
| 47 | |||
| 48 | $inputFilter->add( |
||
| 49 | [ |
||
| 50 | 'name' => 'page_id', |
||
| 51 | 'required' => false, |
||
| 52 | 'filters' => [['name' => 'Null']], |
||
| 53 | 'validators' => [ |
||
| 54 | [ |
||
| 55 | 'name' => RecordExists::class, |
||
| 56 | 'options' => ['table' => 'page', 'field' => 'page_id', 'adapter' => $this->db], |
||
| 57 | ], |
||
| 58 | ], |
||
| 59 | ] |
||
| 60 | ); |
||
| 61 | |||
| 62 | $inputFilter->add( |
||
| 63 | [ |
||
| 64 | 'name' => 'category_id', |
||
| 65 | 'required' => false, |
||
| 66 | 'filters' => [['name' => 'Null']], |
||
| 67 | 'validators' => [ |
||
| 68 | [ |
||
| 69 | 'name' => RecordExists::class, |
||
| 70 | 'options' => ['table' => 'category', 'field' => 'category_id', 'adapter' => $this->db], |
||
| 71 | ], |
||
| 72 | ], |
||
| 73 | ] |
||
| 74 | ); |
||
| 75 | |||
| 76 | $inputFilter->add( |
||
| 77 | [ |
||
| 78 | 'name' => 'is_active', |
||
| 79 | 'required' => false, |
||
| 80 | 'filters' => [['name' => 'Boolean']], |
||
| 81 | ] |
||
| 82 | ); |
||
| 83 | |||
| 84 | $inputFilter->add( |
||
| 85 | [ |
||
| 86 | 'name' => 'is_in_header', |
||
| 87 | 'required' => false, |
||
| 88 | 'filters' => [['name' => 'Boolean']], |
||
| 89 | ] |
||
| 90 | ); |
||
| 91 | |||
| 92 | $inputFilter->add( |
||
| 93 | [ |
||
| 94 | 'name' => 'is_in_footer', |
||
| 95 | 'required' => false, |
||
| 96 | 'filters' => [['name' => 'Boolean']], |
||
| 97 | ] |
||
| 98 | ); |
||
| 99 | |||
| 100 | $inputFilter->add( |
||
| 101 | [ |
||
| 102 | 'name' => 'is_in_side', |
||
| 103 | 'required' => false, |
||
| 104 | 'filters' => [['name' => 'Boolean']], |
||
| 105 | ] |
||
| 106 | ); |
||
| 107 | |||
| 108 | $this->inputFilter = $inputFilter; |
||
| 109 | } |
||
| 110 | |||
| 111 | return $this->inputFilter; |
||
| 112 | } |
||
| 113 | |||
| 119 |