Conditions | 2 |
Paths | 2 |
Total Lines | 64 |
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' => 'slug', |
||
23 | 'required' => true, |
||
24 | 'filters' => [['name' => 'StringTrim', 'options' => ['charlist' => '/']]], |
||
25 | 'validators' => [ |
||
26 | ['name' => 'NotEmpty'], |
||
27 | ['name' => 'StringLength', 'options' => ['min' => 2, 'max' => 100]], |
||
28 | ], |
||
29 | ] |
||
30 | ); |
||
31 | |||
32 | $inputFilter->add( |
||
33 | [ |
||
34 | 'name' => 'published_at', |
||
35 | 'required' => true, |
||
36 | 'filters' => [['name' => 'StringTrim']], |
||
37 | 'validators' => [ |
||
38 | ['name' => 'NotEmpty'], |
||
39 | ['name' => 'Date', 'options' => ['format' => 'Y-m-d H:i:s']], |
||
40 | ], |
||
41 | ] |
||
42 | ); |
||
43 | |||
44 | $inputFilter->add( |
||
45 | [ |
||
46 | 'name' => 'category_id', |
||
47 | 'required' => true, |
||
48 | ] |
||
49 | ); |
||
50 | |||
51 | $inputFilter->add( |
||
52 | [ |
||
53 | 'name' => 'admin_user_id', |
||
54 | 'required' => true, |
||
55 | ] |
||
56 | ); |
||
57 | |||
58 | $inputFilter->add( |
||
59 | [ |
||
60 | 'name' => 'status', |
||
61 | 'required' => false, |
||
62 | 'filters' => [['name' => 'Boolean']], |
||
63 | ] |
||
64 | ); |
||
65 | |||
66 | $inputFilter->add( |
||
67 | [ |
||
68 | 'name' => 'is_wysiwyg_editor', |
||
69 | 'required' => false, |
||
70 | 'filters' => [['name' => 'Boolean']], |
||
71 | ] |
||
72 | ); |
||
73 | |||
74 | $this->inputFilter = $inputFilter; |
||
75 | } |
||
76 | |||
77 | return $this->inputFilter; |
||
78 | } |
||
79 | |||
85 |