Conditions | 1 |
Paths | 1 |
Total Lines | 76 |
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 |
||
127 | public function testQueryBuilderParentId(): void |
||
128 | { |
||
129 | $client = $this->_getClient(); |
||
130 | $index = $client->getIndex('testparentid'); |
||
131 | $index->create([], true); |
||
132 | |||
133 | $mapping = new Mapping([ |
||
134 | 'firstname' => ['type' => 'text', 'store' => true], |
||
135 | 'lastname' => ['type' => 'text'], |
||
136 | 'my_join_field' => [ |
||
137 | 'type' => 'join', |
||
138 | 'relations' => [ |
||
139 | 'question' => 'answer', |
||
140 | ], |
||
141 | ], |
||
142 | ]); |
||
143 | |||
144 | $index->setMapping($mapping); |
||
145 | $index->refresh(); |
||
146 | |||
147 | $doc1 = $index->createDocument('1', [ |
||
148 | 'text' => 'this is the 1st question', |
||
149 | 'my_join_field' => [ |
||
150 | 'name' => 'question', |
||
151 | ], |
||
152 | ]); |
||
153 | |||
154 | $doc2 = $index->createDocument('2', [ |
||
155 | 'text' => 'this is the 2nd question', |
||
156 | 'my_join_field' => [ |
||
157 | 'name' => 'question', |
||
158 | ], |
||
159 | ]); |
||
160 | $index->addDocuments([$doc1, $doc2]); |
||
161 | |||
162 | $doc3 = $index->createDocument('3', [ |
||
163 | 'text' => 'this is an answer, the 1st', |
||
164 | 'my_join_field' => [ |
||
165 | 'name' => 'answer', |
||
166 | 'parent' => 1, |
||
167 | ], |
||
168 | ]); |
||
169 | $doc4 = $index->createDocument('4', [ |
||
170 | 'text' => 'this is an answer, the 2nd', |
||
171 | 'my_join_field' => [ |
||
172 | 'name' => 'answer', |
||
173 | 'parent' => 2, |
||
174 | ], |
||
175 | ]); |
||
176 | $doc5 = $index->createDocument('5', [ |
||
177 | 'text' => 'this is an answer, the 3rd', |
||
178 | 'my_join_field' => [ |
||
179 | 'name' => 'answer', |
||
180 | 'parent' => 2, |
||
181 | ], |
||
182 | ]); |
||
183 | $this->_getClient()->addDocuments([$doc3, $doc4, $doc5], ['routing' => 1]); |
||
184 | $index->refresh(); |
||
185 | |||
186 | $queryDSL = new Query(); |
||
187 | $parentId = $queryDSL->parent_id('answer', 1, true); |
||
188 | $search = new Search($index->getClient()); |
||
189 | $results = $search->search($parentId); |
||
190 | |||
191 | $this->assertEquals(1, $results->count()); |
||
192 | |||
193 | $result = $results->current(); |
||
194 | $data = $result->getData(); |
||
195 | $this->assertEquals($data['text'], 'this is an answer, the 1st'); |
||
196 | |||
197 | $parentId = $queryDSL->parent_id('answer', 2, true); |
||
198 | $search = new Search($index->getClient()); |
||
199 | $results = $search->search($parentId); |
||
200 | |||
201 | $this->assertEquals(2, $results->count()); |
||
202 | } |
||
203 | } |
||
204 |
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: