Conditions | 1 |
Paths | 1 |
Total Lines | 64 |
Code Lines | 39 |
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 |
||
66 | public function testEmptyString() |
||
67 | { |
||
68 | // Case A: empty value in the top level of the source |
||
69 | $field = GroupedDropdownField::create( |
||
70 | 'Test', |
||
71 | 'Testing', |
||
72 | [ |
||
73 | "" => "(Choose A)", |
||
74 | "1" => "One", |
||
75 | "Group One" => [ |
||
76 | "2" => "Two", |
||
77 | "3" => "Three" |
||
78 | ], |
||
79 | "Group Two" => [ |
||
80 | "4" => "Four" |
||
81 | ], |
||
82 | ] |
||
83 | ); |
||
84 | |||
85 | $this->assertRegExp( |
||
86 | '/<option value="" selected="selected" >\(Choose A\)<\/option>/', |
||
87 | preg_replace('/\s+/', ' ', (string)$field->Field()) |
||
88 | ); |
||
89 | |||
90 | // Case B: empty value in the nested level of the source |
||
91 | $field = GroupedDropdownField::create( |
||
92 | 'Test', |
||
93 | 'Testing', |
||
94 | [ |
||
95 | "1" => "One", |
||
96 | "Group One" => [ |
||
97 | "" => "(Choose B)", |
||
98 | "2" => "Two", |
||
99 | "3" => "Three" |
||
100 | ], |
||
101 | "Group Two" => [ |
||
102 | "4" => "Four" |
||
103 | ], |
||
104 | ] |
||
105 | ); |
||
106 | $this->assertRegExp( |
||
107 | '/<option value="" selected="selected" >\(Choose B\)<\/option>/', |
||
108 | preg_replace('/\s+/', ' ', (string)$field->Field()) |
||
109 | ); |
||
110 | |||
111 | // Case C: setEmptyString |
||
112 | $field = GroupedDropdownField::create( |
||
113 | 'Test', |
||
114 | 'Testing', |
||
115 | [ |
||
116 | "1" => "One", |
||
117 | "Group One" => [ |
||
118 | "2" => "Two", |
||
119 | "3" => "Three" |
||
120 | ], |
||
121 | "Group Two" => [ |
||
122 | "4" => "Four" |
||
123 | ], |
||
124 | ] |
||
125 | ); |
||
126 | $field->setEmptyString('(Choose C)'); |
||
127 | $this->assertRegExp( |
||
128 | '/<option value="" selected="selected" >\(Choose C\)<\/option>/', |
||
129 | preg_replace('/\s+/', ' ', (string)$field->Field()) |
||
130 | ); |
||
133 |