Conditions | 1 |
Paths | 1 |
Total Lines | 54 |
Code Lines | 38 |
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 |
||
25 | public function getInputFilter() |
||
26 | { |
||
27 | $inputFilter = new InputFilter(); |
||
28 | |||
29 | $inputFilter |
||
30 | ->add([ |
||
31 | 'name' => 'name', |
||
32 | 'required' => true, |
||
33 | 'filters' => [['name' => 'StringTrim']], |
||
34 | 'validators' => [ |
||
35 | ['name' => 'NotEmpty'], |
||
36 | ['name' => 'StringLength', 'options' => ['min' => 1, 'max' => 255]], |
||
37 | ], |
||
38 | ]) |
||
39 | ->add([ |
||
40 | 'name' => 'email', |
||
41 | 'required' => true, |
||
42 | 'filters' => [['name' => 'StringTrim']], |
||
43 | 'validators' => [ |
||
44 | ['name' => 'NotEmpty'], |
||
45 | ['name' => 'EmailAddress'], |
||
46 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 100]], |
||
47 | ] |
||
48 | ]) |
||
49 | ->add([ |
||
50 | 'name' => 'phone', |
||
51 | 'required' => false, |
||
52 | 'filters' => [['name' => 'StringTrim']], |
||
53 | 'validators' => [ |
||
54 | // TODO: PhoneNumber match cases. |
||
55 | ] |
||
56 | ]) |
||
57 | ->add([ |
||
58 | 'name' => 'subject', |
||
59 | 'required' => true, |
||
60 | 'filters' => [['name' => 'StringTrim']], |
||
61 | 'validators' => [ |
||
62 | ['name' => 'NotEmpty'], |
||
63 | ['name' => 'StringLength', 'options' => ['min' => 5]] |
||
64 | ] |
||
65 | ]) |
||
66 | ->add([ |
||
67 | 'name' => 'body', |
||
68 | 'required' => true, |
||
69 | 'filters' => [['name' => 'StringTrim']], |
||
70 | 'validators' => [ |
||
71 | ['name' => 'NotEmpty'], |
||
72 | ['name' => 'StringLength', 'options' => ['min' => 5]] |
||
73 | ] |
||
74 | ]) |
||
75 | ; |
||
76 | |||
77 | return $inputFilter; |
||
78 | } |
||
79 | |||
92 | } |