| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 68 | 
| 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 | ||
| 147 | public function testMultipleQueries(): void | ||
| 148 |     { | ||
| 149 | $query = new Query(); | ||
| 150 | $mainQuery = new MatchQuery(); | ||
| 151 |         $mainQuery = $mainQuery->setFieldQuery('test1', 'foo'); | ||
| 152 | |||
| 153 | $secQuery1 = new Term(); | ||
| 154 |         $secQuery1 = $secQuery1->setTerm('test2', 'bar', 1); | ||
| 155 | $rescoreQuery1 = new QueryRescore(); | ||
| 156 | $rescoreQuery1->setRescoreQuery($secQuery1); | ||
| 157 | |||
| 158 | $secQuery2 = new Term(); | ||
| 159 |         $secQuery2 = $secQuery2->setTerm('test2', 'tom', 2); | ||
| 160 | $rescoreQuery2 = new QueryRescore(); | ||
| 161 | $rescoreQuery2->setRescoreQuery($secQuery2); | ||
| 162 | |||
| 163 | $query->setQuery($mainQuery); | ||
| 164 | $query->setRescore([$rescoreQuery1, $rescoreQuery2]); | ||
| 165 | $data = $query->toArray(); | ||
| 166 | |||
| 167 | $expected = [ | ||
| 168 | 'query' => [ | ||
| 169 | 'match' => [ | ||
| 170 | 'test1' => [ | ||
| 171 | 'query' => 'foo', | ||
| 172 | ], | ||
| 173 | ], | ||
| 174 | ], | ||
| 175 | 'rescore' => [ | ||
| 176 | [ | ||
| 177 | 'query' => [ | ||
| 178 | 'rescore_query' => [ | ||
| 179 | 'term' => [ | ||
| 180 | 'test2' => [ | ||
| 181 | 'value' => 'bar', | ||
| 182 | 'boost' => 1, | ||
| 183 | ], | ||
| 184 | ], | ||
| 185 | ], | ||
| 186 | ], | ||
| 187 | ], | ||
| 188 | [ | ||
| 189 | 'query' => [ | ||
| 190 | 'rescore_query' => [ | ||
| 191 | 'term' => [ | ||
| 192 | 'test2' => [ | ||
| 193 | 'value' => 'tom', | ||
| 194 | 'boost' => 2, | ||
| 195 | ], | ||
| 196 | ], | ||
| 197 | ], | ||
| 198 | ], | ||
| 199 | ], | ||
| 200 | ], | ||
| 201 | ]; | ||
| 202 | |||
| 203 | $this->assertEquals($expected, $data); | ||
| 204 | |||
| 205 | $index = $this->_createIndex(); | ||
| 206 | $index->refresh(); | ||
| 207 | $index->forcemerge(); | ||
| 208 | |||
| 209 | $results = $index->search($query); | ||
| 210 | $response = $results->getResponse(); | ||
| 211 | |||
| 212 | $this->assertEquals(true, $response->isOk()); | ||
| 213 | $this->assertEquals(0, $results->getTotalHits()); | ||
| 214 | } | ||
| 215 | |||
| 245 | 
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.