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