| Conditions | 2 |
| Paths | 2 |
| Total Lines | 58 |
| Code Lines | 38 |
| 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 |
||
| 89 | public function testLinks() |
||
| 90 | { |
||
| 91 | // Run link checker |
||
| 92 | $task = CheckExternalLinksTask::create(); |
||
| 93 | $task->setSilent(true); // Be quiet during the test! |
||
| 94 | $task->runLinksCheck(); |
||
| 95 | |||
| 96 | // Get all links checked |
||
| 97 | $status = BrokenExternalPageTrackStatus::get_latest(); |
||
| 98 | $this->assertEquals('Completed', $status->Status); |
||
| 99 | $this->assertEquals(5, $status->TotalPages); |
||
| 100 | $this->assertEquals(5, $status->CompletedPages); |
||
| 101 | |||
| 102 | // Check all pages have had the correct HTML adjusted |
||
| 103 | for ($i = 1; $i <= 5; $i++) { |
||
| 104 | $page = $this->objFromFixture('ExternalLinksTestPage', 'page'.$i); |
||
| 105 | $this->assertNotEmpty($page->Content); |
||
| 106 | $this->assertEquals( |
||
| 107 | $page->ExpectedContent, |
||
| 108 | $page->Content, |
||
| 109 | "Assert that the content of page{$i} has been updated" |
||
| 110 | ); |
||
| 111 | } |
||
| 112 | |||
| 113 | // Check that the correct report of broken links is generated |
||
| 114 | $links = $status |
||
| 115 | ->BrokenLinks() |
||
| 116 | ->sort('Link'); |
||
| 117 | |||
| 118 | $this->assertEquals(4, $links->count()); |
||
| 119 | $this->assertEquals( |
||
| 120 | array( |
||
| 121 | 'http://www.broken.com', |
||
| 122 | 'http://www.broken.com/url/thing', |
||
| 123 | 'http://www.broken.com/url/thing', |
||
| 124 | 'http://www.nodomain.com' |
||
| 125 | ), |
||
| 126 | array_values($links->map('ID', 'Link')->toArray()) |
||
| 127 | ); |
||
| 128 | |||
| 129 | // Check response codes are correct |
||
| 130 | $expected = array( |
||
| 131 | 'http://www.broken.com' => 403, |
||
| 132 | 'http://www.broken.com/url/thing' => 404, |
||
| 133 | 'http://www.nodomain.com' => 0 |
||
| 134 | ); |
||
| 135 | $actual = $links->map('Link', 'HTTPCode')->toArray(); |
||
| 136 | $this->assertEquals($expected, $actual); |
||
| 137 | |||
| 138 | // Check response descriptions are correct |
||
| 139 | i18n::set_locale('en_NZ'); |
||
| 140 | $expected = array( |
||
| 141 | 'http://www.broken.com' => '403 (Forbidden)', |
||
| 142 | 'http://www.broken.com/url/thing' => '404 (Not Found)', |
||
| 143 | 'http://www.nodomain.com' => '0 (Server Not Available)' |
||
| 144 | ); |
||
| 145 | $actual = $links->map('Link', 'HTTPCodeDescription')->toArray(); |
||
| 146 | $this->assertEquals($expected, $actual); |
||
| 147 | } |
||
| 166 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.