Conditions | 1 |
Paths | 1 |
Total Lines | 52 |
Code Lines | 41 |
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 |
||
29 | public function testSendEmail() { |
||
30 | $author = $this->objFromFixture('Member', 'author'); |
||
31 | $item1 = $this->objFromFixture('CommentNotifiableTest_DataObject', 'item1'); |
||
32 | $item2 = $this->objFromFixture('CommentNotifiableTest_DataObject', 'item2'); |
||
33 | $comment1 = $this->objFromFixture('Comment', 'comment1'); |
||
34 | $comment2 = $this->objFromFixture('Comment', 'comment2'); |
||
35 | $comment3 = $this->objFromFixture('Comment', 'comment3'); |
||
36 | $controller = new CommentNotifierTest_Controller(); |
||
37 | |||
38 | |||
39 | // Commen 1 |
||
40 | $result = $controller->notifyCommentRecipient($comment1, $item1, $author); |
||
41 | $this->assertEquals('[email protected]', $result['to']); |
||
42 | $this->assertEquals('[email protected]', $result['from']); |
||
43 | $this->assertEquals('A new comment has been posted', $result['subject']); |
||
44 | $this->assertContains('<li>Bob Bobberson</li>', $result['content']); |
||
45 | $this->assertContains('<li>[email protected]</li>', $result['content']); |
||
46 | $this->assertContains('<blockquote>Hey what a lovely comment</blockquote>', $result['content']); |
||
47 | $this->assertContains( |
||
48 | 'You can view or moderate this comment at <a href="http://www.mysite.com/item1#comment-' . |
||
49 | $comment1->ID . '">An Object</a>', |
||
50 | $result['content'] |
||
51 | ); |
||
52 | |||
53 | // Comment 2 |
||
54 | $result = $controller->notifyCommentRecipient($comment2, $item2, $author); |
||
55 | $this->assertEquals('[email protected]', $result['to']); |
||
56 | $this->assertEquals('[email protected]', $result['from']); |
||
57 | $this->assertEquals('A new comment has been posted', $result['subject']); |
||
58 | $this->assertContains('<li>Secret</li>', $result['content']); |
||
59 | $this->assertContains('<li>[email protected]</li>', $result['content']); |
||
60 | $this->assertContains('<blockquote>I don't want to disclose my details</blockquote>', $result['content']); |
||
61 | $this->assertContains( |
||
62 | 'You can view or moderate this comment at <a href="http://www.mysite.com/item2#comment-' . |
||
63 | $comment2->ID . '">Another One</a>', |
||
64 | $result['content'] |
||
65 | ); |
||
66 | |||
67 | // Comment 3 |
||
68 | $result = $controller->notifyCommentRecipient($comment3, $item1, $author); |
||
69 | $this->assertEquals('[email protected]', $result['to']); |
||
70 | $this->assertEquals('[email protected]', $result['from']); |
||
71 | $this->assertEquals('A new comment has been posted', $result['subject']); |
||
72 | $this->assertContains('<li>Anonymous</li>', $result['content']); |
||
73 | $this->assertContains('<li>[email protected]</li>', $result['content']); |
||
74 | $this->assertContains('<blockquote>I didn't log in</blockquote>', $result['content']); |
||
75 | $this->assertContains( |
||
76 | 'You can view or moderate this comment at <a href="http://www.mysite.com/item1#comment-' . |
||
77 | $comment3->ID . '">An Object</a>', |
||
78 | $result['content'] |
||
79 | ); |
||
80 | } |
||
81 | } |
||
87 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.