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