| Conditions | 2 |
| Paths | 2 |
| Total Lines | 58 |
| Code Lines | 39 |
| 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 |
||
| 80 | public function testLinks() { |
||
| 81 | // Run link checker |
||
| 82 | $task = CheckExternalLinksTask::create(); |
||
| 83 | $task->setSilent(true); // Be quiet during the test! |
||
| 84 | $task->runLinksCheck(); |
||
| 85 | |||
| 86 | // Get all links checked |
||
| 87 | $status = BrokenExternalPageTrackStatus::get_latest(); |
||
| 88 | $this->assertEquals('Completed', $status->Status); |
||
| 89 | $this->assertEquals(5, $status->TotalPages); |
||
| 90 | $this->assertEquals(5, $status->CompletedPages); |
||
| 91 | |||
| 92 | // Check all pages have had the correct HTML adjusted |
||
| 93 | for($i = 1; $i <= 5; $i++) { |
||
| 94 | $page = $this->objFromFixture('ExternalLinksTest_Page', 'page'.$i); |
||
| 95 | $this->assertNotEmpty($page->Content); |
||
| 96 | $this->assertEquals( |
||
| 97 | $page->ExpectedContent, |
||
| 98 | $page->Content, |
||
| 99 | "Assert that the content of page{$i} has been updated" |
||
| 100 | ); |
||
| 101 | } |
||
| 102 | |||
| 103 | // Check that the correct report of broken links is generated |
||
| 104 | $links = $status |
||
| 105 | ->BrokenLinks() |
||
| 106 | ->sort('Link'); |
||
| 107 | |||
| 108 | $this->assertEquals(4, $links->count()); |
||
| 109 | $this->assertEquals( |
||
| 110 | array( |
||
| 111 | 'http://www.broken.com', |
||
| 112 | 'http://www.broken.com/url/thing', |
||
| 113 | 'http://www.broken.com/url/thing', |
||
| 114 | 'http://www.nodomain.com' |
||
| 115 | ), |
||
| 116 | array_values($links->map('ID', 'Link')->toArray()) |
||
| 117 | ); |
||
| 118 | |||
| 119 | // Check response codes are correct |
||
| 120 | $expected = array( |
||
| 121 | 'http://www.broken.com' => 403, |
||
| 122 | 'http://www.broken.com/url/thing' => 404, |
||
| 123 | 'http://www.nodomain.com' => 0 |
||
| 124 | ); |
||
| 125 | $actual = $links->map('Link', 'HTTPCode')->toArray(); |
||
| 126 | $this->assertEquals($expected, $actual); |
||
| 127 | |||
| 128 | // Check response descriptions are correct |
||
| 129 | i18n::set_locale('en_NZ'); |
||
| 130 | $expected = array( |
||
| 131 | 'http://www.broken.com' => '403 (Forbidden)', |
||
| 132 | 'http://www.broken.com/url/thing' => '404 (Not Found)', |
||
| 133 | 'http://www.nodomain.com' => '0 (Server Not Available)' |
||
| 134 | ); |
||
| 135 | $actual = $links->map('Link', 'HTTPCodeDescription')->toArray(); |
||
| 136 | $this->assertEquals($expected, $actual); |
||
| 137 | } |
||
| 138 | |||
| 158 |
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.