Conditions | 1 |
Paths | 1 |
Total Lines | 81 |
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 |
||
40 | public function testSupportsControllerAndAction() |
||
41 | { |
||
42 | $plugin = new TestPlugin(array()); |
||
43 | |||
44 | // no lists yet, so plugin supports everything |
||
45 | $this->assertTrue( |
||
46 | $plugin->supportsControllerAndAction( |
||
47 | 'TestController', |
||
48 | 'anyAction' |
||
49 | ) |
||
50 | ); |
||
51 | |||
52 | // set a whitelist |
||
53 | $plugin->setWhitelist( |
||
54 | array( |
||
55 | 'TestController' => AbstractPlugin::ALL_ACTIONS, |
||
56 | 'AnotherController' => array( |
||
57 | 'specificAction' |
||
58 | ) |
||
59 | ) |
||
60 | ); |
||
61 | // all actions enabled for this controller |
||
62 | $this->assertTrue( |
||
63 | $plugin->supportsControllerAndAction( |
||
64 | 'TestController', |
||
65 | 'anyAction' |
||
66 | ) |
||
67 | ); |
||
68 | // specific action enabled |
||
69 | $this->assertTrue( |
||
70 | $plugin->supportsControllerAndAction( |
||
71 | 'AnotherController', |
||
72 | 'specificAction' |
||
73 | ) |
||
74 | ); |
||
75 | // controller is missing from whitelist |
||
76 | $this->assertFalse( |
||
77 | $plugin->supportsControllerAndAction( |
||
78 | 'MissingController', |
||
79 | 'anyAction' |
||
80 | ) |
||
81 | ); |
||
82 | // action is missing from whitelist |
||
83 | $this->assertFalse( |
||
84 | $plugin->supportsControllerAndAction( |
||
85 | 'AnotherController', |
||
86 | 'differentAction' |
||
87 | ) |
||
88 | ); |
||
89 | |||
90 | // now the reverse logic for the blacklist |
||
91 | $plugin->setBlacklist( |
||
92 | array( |
||
93 | 'TestController' => array( |
||
94 | 'bannedAction' |
||
95 | ), |
||
96 | 'BannedController' => AbstractPlugin::ALL_ACTIONS |
||
97 | ) |
||
98 | ); |
||
99 | // controller is missing from blacklist |
||
100 | $this->assertTrue( |
||
101 | $plugin->supportsControllerAndAction( |
||
102 | 'MissingController', |
||
103 | 'anyAction' |
||
104 | ) |
||
105 | ); |
||
106 | // action is blacklisted specifically |
||
107 | $this->assertFalse( |
||
108 | $plugin->supportsControllerAndAction( |
||
109 | 'TestController', |
||
110 | 'bannedAction' |
||
111 | ) |
||
112 | ); |
||
113 | // all actions for the controller are banned |
||
114 | $this->assertFalse( |
||
115 | $plugin->supportsControllerAndAction( |
||
116 | 'BannedController', |
||
117 | 'anyAction' |
||
118 | ) |
||
119 | ); |
||
120 | } |
||
121 | } |
||
122 |