Conditions | 1 |
Paths | 1 |
Total Lines | 83 |
Code Lines | 59 |
Lines | 0 |
Ratio | 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 |
||
18 | public function testHttpMethodOverrides() { |
||
19 | $request = new SS_HTTPRequest( |
||
20 | 'GET', |
||
21 | 'admin/crm' |
||
22 | ); |
||
23 | $this->assertTrue( |
||
24 | $request->isGET(), |
||
25 | 'GET with no method override' |
||
26 | ); |
||
27 | |||
28 | $request = new SS_HTTPRequest( |
||
29 | 'POST', |
||
30 | 'admin/crm' |
||
31 | ); |
||
32 | $this->assertTrue( |
||
33 | $request->isPOST(), |
||
34 | 'POST with no method override' |
||
35 | ); |
||
36 | |||
37 | $request = new SS_HTTPRequest( |
||
38 | 'GET', |
||
39 | 'admin/crm', |
||
40 | array('_method' => 'DELETE') |
||
41 | ); |
||
42 | $this->assertTrue( |
||
43 | $request->isGET(), |
||
44 | 'GET with invalid POST method override' |
||
45 | ); |
||
46 | |||
47 | $request = new SS_HTTPRequest( |
||
48 | 'POST', |
||
49 | 'admin/crm', |
||
50 | array(), |
||
51 | array('_method' => 'DELETE') |
||
52 | ); |
||
53 | $this->assertTrue( |
||
54 | $request->isDELETE(), |
||
55 | 'POST with valid method override to DELETE' |
||
56 | ); |
||
57 | |||
58 | $request = new SS_HTTPRequest( |
||
59 | 'POST', |
||
60 | 'admin/crm', |
||
61 | array(), |
||
62 | array('_method' => 'put') |
||
63 | ); |
||
64 | $this->assertTrue( |
||
65 | $request->isPUT(), |
||
66 | 'POST with valid method override to PUT' |
||
67 | ); |
||
68 | |||
69 | $request = new SS_HTTPRequest( |
||
70 | 'POST', |
||
71 | 'admin/crm', |
||
72 | array(), |
||
73 | array('_method' => 'head') |
||
74 | ); |
||
75 | $this->assertTrue( |
||
76 | $request->isHEAD(), |
||
77 | 'POST with valid method override to HEAD ' |
||
78 | ); |
||
79 | |||
80 | $request = new SS_HTTPRequest( |
||
81 | 'POST', |
||
82 | 'admin/crm', |
||
83 | array(), |
||
84 | array('_method' => 'head') |
||
85 | ); |
||
86 | $this->assertTrue( |
||
87 | $request->isHEAD(), |
||
88 | 'POST with valid method override to HEAD' |
||
89 | ); |
||
90 | |||
91 | $request = new SS_HTTPRequest( |
||
92 | 'POST', |
||
93 | 'admin/crm', |
||
94 | array('_method' => 'head') |
||
95 | ); |
||
96 | $this->assertTrue( |
||
97 | $request->isPOST(), |
||
98 | 'POST with invalid method override by GET parameters to HEAD' |
||
99 | ); |
||
100 | } |
||
101 | |||
277 |