| 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 |
||
| 54 | public function testSearchWithAnalyzer(): void |
||
| 55 | { |
||
| 56 | $client = $this->_getClient(); |
||
| 57 | $index = $client->getIndex('test'); |
||
| 58 | |||
| 59 | $indexParams = [ |
||
| 60 | 'settings' => [ |
||
| 61 | 'analysis' => [ |
||
| 62 | 'analyzer' => [ |
||
| 63 | 'lw' => [ |
||
| 64 | 'type' => 'custom', |
||
| 65 | 'tokenizer' => 'keyword', |
||
| 66 | 'filter' => ['lowercase'], |
||
| 67 | ], |
||
| 68 | ], |
||
| 69 | ], |
||
| 70 | ], |
||
| 71 | ]; |
||
| 72 | |||
| 73 | $index->create($indexParams, ['recreate' => true]); |
||
| 74 | |||
| 75 | $mapping = new Mapping([ |
||
| 76 | 'name' => ['type' => 'text', 'analyzer' => 'lw'], |
||
| 77 | ]); |
||
| 78 | $index->setMapping($mapping); |
||
| 79 | |||
| 80 | $index->addDocuments([ |
||
| 81 | new Document(1, ['name' => 'Basel-Stadt']), |
||
| 82 | new Document(2, ['name' => 'New York']), |
||
| 83 | new Document(3, ['name' => 'Baden']), |
||
| 84 | new Document(4, ['name' => 'Baden Baden']), |
||
| 85 | new Document(5, ['name' => 'New Orleans']), |
||
| 86 | ]); |
||
| 87 | |||
| 88 | $index->refresh(); |
||
| 89 | |||
| 90 | $query = new Wildcard('name', 'ba*'); |
||
| 91 | $resultSet = $index->search($query); |
||
|
|
|||
| 92 | |||
| 93 | $this->assertEquals(3, $resultSet->count()); |
||
| 94 | |||
| 95 | $query = new Wildcard('name', 'baden*'); |
||
| 96 | $resultSet = $index->search($query); |
||
| 97 | |||
| 98 | $this->assertEquals(2, $resultSet->count()); |
||
| 99 | |||
| 100 | $query = new Wildcard('name', 'baden b*'); |
||
| 101 | $resultSet = $index->search($query); |
||
| 102 | |||
| 103 | $this->assertEquals(1, $resultSet->count()); |
||
| 104 | |||
| 105 | $query = new Wildcard('name', 'baden bas*'); |
||
| 106 | $resultSet = $index->search($query); |
||
| 107 | |||
| 108 | $this->assertEquals(0, $resultSet->count()); |
||
| 109 | } |
||
| 110 | |||
| 136 |
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: