Conditions | 2 |
Paths | 2 |
Total Lines | 70 |
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 |
||
15 | public function getInputFilter() |
||
16 | { |
||
17 | if (!$this->inputFilter) { |
||
18 | $inputFilter = new InputFilter(); |
||
19 | |||
20 | $inputFilter->add( |
||
21 | [ |
||
22 | 'name' => 'title', |
||
23 | 'required' => true, |
||
24 | 'filters' => [['name' => 'StringTrim']], |
||
25 | 'validators' => [ |
||
26 | ['name' => 'NotEmpty'], |
||
27 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 100]], |
||
28 | ], |
||
29 | ] |
||
30 | ); |
||
31 | |||
32 | $inputFilter->add( |
||
33 | [ |
||
34 | 'name' => 'sub_title', |
||
35 | 'required' => false, |
||
36 | 'filters' => [['name' => 'StringTrim']], |
||
37 | 'validators' => [ |
||
38 | ['name' => 'NotEmpty'], |
||
39 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 500]], |
||
40 | ], |
||
41 | ] |
||
42 | ); |
||
43 | |||
44 | $inputFilter->add( |
||
45 | [ |
||
46 | 'name' => 'body', |
||
47 | 'required' => true, |
||
48 | 'filters' => [['name' => 'StringTrim']], |
||
49 | 'validators' => [ |
||
50 | ['name' => 'NotEmpty'], |
||
51 | ['name' => 'StringLength', 'options' => ['min' => 2]], |
||
52 | ], |
||
53 | ] |
||
54 | ); |
||
55 | |||
56 | $inputFilter->add( |
||
57 | [ |
||
58 | 'name' => 'lead', |
||
59 | 'required' => true, |
||
60 | 'filters' => [['name' => 'StringTrim']], |
||
61 | 'validators' => [ |
||
62 | ['name' => 'NotEmpty'], |
||
63 | ['name' => 'StringLength', 'options' => ['min' => 2]], |
||
64 | ], |
||
65 | ] |
||
66 | ); |
||
67 | |||
68 | $inputFilter->add( |
||
69 | [ |
||
70 | 'name' => 'video_url', |
||
71 | 'required' => true, |
||
72 | 'filters' => [['name' => 'StringTrim']], |
||
73 | 'validators' => [ |
||
74 | ['name' => 'NotEmpty'], |
||
75 | ['name' => 'StringLength'], |
||
76 | ], |
||
77 | ] |
||
78 | ); |
||
79 | |||
80 | $this->inputFilter = $inputFilter; |
||
81 | } |
||
82 | |||
83 | return $this->inputFilter; |
||
84 | } |
||
85 | |||
91 |