Conditions | 1 |
Paths | 1 |
Total Lines | 88 |
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 |
||
183 | public function testFilterFeatureWithTaggedExamples() |
||
184 | { |
||
185 | $exampleTableNode1 = new ExampleTableNode(array(), null, array('etag1', 'etag2')); |
||
186 | $exampleTableNode2 = new ExampleTableNode(array(), null, array('etag2', 'etag3')); |
||
187 | $scenario = new OutlineNode(null, array('wip'), array(), array( |
||
188 | $exampleTableNode1, |
||
189 | $exampleTableNode2, |
||
190 | ), null, 2); |
||
191 | $feature = new FeatureNode(null, null, array('feature-tag'), null, array($scenario), null, null, null, 1); |
||
192 | |||
193 | $tagFilter = new TagFilter('@etag2'); |
||
194 | $matched = $tagFilter->filterFeature($feature); |
||
195 | $scenarioInterfaces = $matched->getScenarios(); |
||
196 | $this->assertEquals($scenario, $scenarioInterfaces[0]); |
||
197 | |||
198 | $tagFilter = new TagFilter('@etag1'); |
||
199 | $matched = $tagFilter->filterFeature($feature); |
||
200 | $scenarioInterfaces = $matched->getScenarios(); |
||
201 | /** @noinspection PhpUndefinedMethodInspection */ |
||
202 | $this->assertEquals(array($exampleTableNode1), $scenarioInterfaces[0]->getExampleTables()); |
||
|
|||
203 | |||
204 | $tagFilter = new TagFilter('~@etag3'); |
||
205 | $matched = $tagFilter->filterFeature($feature); |
||
206 | $scenarioInterfaces = $matched->getScenarios(); |
||
207 | /** @noinspection PhpUndefinedMethodInspection */ |
||
208 | $this->assertEquals(array($exampleTableNode1), $scenarioInterfaces[0]->getExampleTables()); |
||
209 | |||
210 | $tagFilter = new TagFilter('@wip'); |
||
211 | $matched = $tagFilter->filterFeature($feature); |
||
212 | $scenarioInterfaces = $matched->getScenarios(); |
||
213 | $this->assertEquals($scenario, $scenarioInterfaces[0]); |
||
214 | |||
215 | $tagFilter = new TagFilter('@wip&&@etag3'); |
||
216 | $matched = $tagFilter->filterFeature($feature); |
||
217 | $scenarioInterfaces = $matched->getScenarios(); |
||
218 | /** @noinspection PhpUndefinedMethodInspection */ |
||
219 | $this->assertEquals(array($exampleTableNode2), $scenarioInterfaces[0]->getExampleTables()); |
||
220 | |||
221 | $tagFilter = new TagFilter('@feature-tag&&@etag1&&@wip'); |
||
222 | $matched = $tagFilter->filterFeature($feature); |
||
223 | $scenarioInterfaces = $matched->getScenarios(); |
||
224 | /** @noinspection PhpUndefinedMethodInspection */ |
||
225 | $this->assertEquals(array($exampleTableNode1), $scenarioInterfaces[0]->getExampleTables()); |
||
226 | |||
227 | $tagFilter = new TagFilter('@feature-tag&&~@etag11111&&@wip'); |
||
228 | $matched = $tagFilter->filterFeature($feature); |
||
229 | $scenarioInterfaces = $matched->getScenarios(); |
||
230 | $this->assertEquals($scenario, $scenarioInterfaces[0]); |
||
231 | |||
232 | $tagFilter = new TagFilter('@feature-tag&&~@etag1&&@wip'); |
||
233 | $matched = $tagFilter->filterFeature($feature); |
||
234 | $scenarioInterfaces = $matched->getScenarios(); |
||
235 | /** @noinspection PhpUndefinedMethodInspection */ |
||
236 | $this->assertEquals(array($exampleTableNode2), $scenarioInterfaces[0]->getExampleTables()); |
||
237 | |||
238 | $tagFilter = new TagFilter('@feature-tag&&@etag2'); |
||
239 | $matched = $tagFilter->filterFeature($feature); |
||
240 | $scenarioInterfaces = $matched->getScenarios(); |
||
241 | $this->assertEquals($scenario, $scenarioInterfaces[0]); |
||
242 | |||
243 | $exampleTableNode1 = new ExampleTableNode(array(), null, array('etag1', 'etag')); |
||
244 | $exampleTableNode2 = new ExampleTableNode(array(), null, array('etag2', 'etag22', 'etag')); |
||
245 | $exampleTableNode3 = new ExampleTableNode(array(), null, array('etag3', 'etag22', 'etag')); |
||
246 | $exampleTableNode4 = new ExampleTableNode(array(), null, array('etag4', 'etag')); |
||
247 | $scenario1 = new OutlineNode(null, array('wip'), array(), array( |
||
248 | $exampleTableNode1, |
||
249 | $exampleTableNode2, |
||
250 | ), null, 2); |
||
251 | $scenario2 = new OutlineNode(null, array('wip'), array(), array( |
||
252 | $exampleTableNode3, |
||
253 | $exampleTableNode4, |
||
254 | ), null, 2); |
||
255 | $feature = new FeatureNode(null, null, array('feature-tag'), null, array($scenario1, $scenario2), null, null, null, 1); |
||
256 | |||
257 | $tagFilter = new TagFilter('@etag'); |
||
258 | $matched = $tagFilter->filterFeature($feature); |
||
259 | $scenarioInterfaces = $matched->getScenarios(); |
||
260 | $this->assertEquals(array($scenario1, $scenario2), $scenarioInterfaces); |
||
261 | |||
262 | $tagFilter = new TagFilter('@etag22'); |
||
263 | $matched = $tagFilter->filterFeature($feature); |
||
264 | $scenarioInterfaces = $matched->getScenarios(); |
||
265 | $this->assertEquals(2, count($scenarioInterfaces)); |
||
266 | /** @noinspection PhpUndefinedMethodInspection */ |
||
267 | $this->assertEquals(array($exampleTableNode2), $scenarioInterfaces[0]->getExampleTables()); |
||
268 | /** @noinspection PhpUndefinedMethodInspection */ |
||
269 | $this->assertEquals(array($exampleTableNode3), $scenarioInterfaces[1]->getExampleTables()); |
||
270 | } |
||
271 | } |
||
272 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: