| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 18 | ||
| Bugs | 1 | Features | 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 |
||
| 124 | public function testDoSearch() |
||
| 125 | { |
||
| 126 | $index = new CircleCITestIndex(); |
||
| 127 | |||
| 128 | $query = new BaseQuery(); |
||
| 129 | $query->addTerm('Home'); |
||
| 130 | |||
| 131 | $result = $index->doSearch($query); |
||
| 132 | $this->assertInstanceOf(SearchResult::class, $result); |
||
| 133 | $this->assertEquals(1, $result->getTotalItems()); |
||
| 134 | |||
| 135 | $admin = singleton(DefaultAdminService::class)->findOrCreateDefaultAdmin(); |
||
| 136 | $this->loginAs($admin); |
||
| 137 | // Result should be the same for now |
||
| 138 | $result2 = $index->doSearch($query); |
||
| 139 | $this->assertEquals($result, $result2); |
||
| 140 | |||
| 141 | $query->addClass(SiteTree::class); |
||
| 142 | |||
| 143 | $result3 = $index->doSearch($query); |
||
| 144 | $request = new NullHTTPRequest(); |
||
| 145 | $this->assertInstanceOf(PaginatedList::class, $result3->getPaginatedMatches($request)); |
||
| 146 | $this->assertEquals($result3->getTotalItems(), $result3->getPaginatedMatches($request)->getTotalItems()); |
||
| 147 | $this->assertInstanceOf(ArrayData::class, $result3->getFacets()); |
||
| 148 | $this->assertInstanceOf(ArrayList::class, $result3->getSpellcheck()); |
||
| 149 | $this->assertInstanceOf(Highlighting::class, $result3->getHighlight()); |
||
| 150 | |||
| 151 | $result3->setCustomisedMatches([]); |
||
| 152 | $this->assertInstanceOf(ArrayList::class, $result3->getMatches()); |
||
| 153 | $this->assertCount(0, $result3->getMatches()); |
||
| 154 | |||
| 155 | $index = new CircleCITestIndex(); |
||
| 156 | $query = new BaseQuery(); |
||
| 157 | $query->addTerm('Home', ['SiteTree_Title'], 5); |
||
| 158 | $result4 = $index->doSearch($query); |
||
| 159 | |||
| 160 | $this->assertContains('SiteTree_Title:Home^5.0', $index->getQueryFactory()->getBoostTerms()); |
||
| 161 | $this->assertContains('Home', $index->getQueryTerms()); |
||
| 162 | $this->assertEquals(1, $result4->getTotalItems()); |
||
| 163 | |||
| 164 | $index = new CircleCITestIndex(); |
||
| 165 | $query = new BaseQuery(); |
||
| 166 | $query->addTerm('Home', ['SiteTree.Title'], 3); |
||
| 167 | $result4 = $index->doSearch($query); |
||
| 168 | |||
| 169 | $this->assertContains('SiteTree_Title:Home^3.0', $index->getQueryFactory()->getBoostTerms()); |
||
| 170 | $this->assertContains('Home', $index->getQueryTerms()); |
||
| 171 | $this->assertEquals(1, $result4->getTotalItems()); |
||
| 172 | |||
| 173 | $index = new CircleCITestIndex(); |
||
| 174 | $query = new BaseQuery(); |
||
| 175 | $query->addTerm('Home', [], 0, true); |
||
| 176 | $index->doSearch($query); |
||
| 177 | |||
| 178 | $this->assertContains('Home~', $index->getQueryTerms()); |
||
| 179 | |||
| 180 | $index = new CircleCITestIndex(); |
||
| 181 | $query = new BaseQuery(); |
||
| 182 | $query->addTerm('Home', [], 0, 2); |
||
| 183 | $index->doSearch($query); |
||
| 184 | |||
| 185 | $this->assertContains('Home~2', $index->getQueryTerms()); |
||
| 186 | } |
||
| 223 |