| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| 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 |
||
| 53 | public function testSearchWithAnalyzer(): void |
||
| 54 | { |
||
| 55 | $client = $this->_getClient(); |
||
| 56 | $index = $client->getIndex('test'); |
||
| 57 | |||
| 58 | $indexParams = [ |
||
| 59 | 'settings' => [ |
||
| 60 | 'analysis' => [ |
||
| 61 | 'analyzer' => [ |
||
| 62 | 'lw' => [ |
||
| 63 | 'type' => 'custom', |
||
| 64 | 'tokenizer' => 'keyword', |
||
| 65 | 'filter' => ['lowercase'], |
||
| 66 | ], |
||
| 67 | ], |
||
| 68 | ], |
||
| 69 | ], |
||
| 70 | ]; |
||
| 71 | |||
| 72 | $index->create($indexParams, ['recreate' => true]); |
||
| 73 | |||
| 74 | $mapping = new Mapping([ |
||
| 75 | 'name' => ['type' => 'text', 'analyzer' => 'lw'], |
||
| 76 | ]); |
||
| 77 | $index->setMapping($mapping); |
||
| 78 | |||
| 79 | $index->addDocuments([ |
||
| 80 | new Document(1, ['name' => 'Basel-Stadt']), |
||
| 81 | new Document(2, ['name' => 'New York']), |
||
| 82 | new Document(3, ['name' => 'Baden']), |
||
| 83 | new Document(4, ['name' => 'Baden Baden']), |
||
| 84 | new Document(5, ['name' => 'New Orleans']), |
||
| 85 | ]); |
||
| 86 | |||
| 87 | $index->refresh(); |
||
| 88 | |||
| 89 | $query = new Wildcard('name', 'ba*'); |
||
| 90 | $resultSet = $index->search($query); |
||
|
|
|||
| 91 | |||
| 92 | $this->assertEquals(3, $resultSet->count()); |
||
| 93 | |||
| 94 | $query = new Wildcard('name', 'baden*'); |
||
| 95 | $resultSet = $index->search($query); |
||
| 96 | |||
| 97 | $this->assertEquals(2, $resultSet->count()); |
||
| 98 | |||
| 99 | $query = new Wildcard('name', 'baden b*'); |
||
| 100 | $resultSet = $index->search($query); |
||
| 101 | |||
| 102 | $this->assertEquals(1, $resultSet->count()); |
||
| 103 | |||
| 104 | $query = new Wildcard('name', 'baden bas*'); |
||
| 105 | $resultSet = $index->search($query); |
||
| 106 | |||
| 107 | $this->assertEquals(0, $resultSet->count()); |
||
| 108 | } |
||
| 109 | |||
| 137 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: