| Conditions | 1 |
| Paths | 1 |
| Total Lines | 87 |
| 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 |
||
| 35 | public function testParentId(): void |
||
| 36 | { |
||
| 37 | $client = $this->_getClient(); |
||
| 38 | $index = $client->getIndex('testparentid'); |
||
| 39 | $index->create([], true); |
||
| 40 | |||
| 41 | $mapping = new Mapping([ |
||
| 42 | 'firstname' => ['type' => 'text', 'store' => true], |
||
| 43 | 'lastname' => ['type' => 'text'], |
||
| 44 | 'my_join_field' => [ |
||
| 45 | 'type' => 'join', |
||
| 46 | 'relations' => [ |
||
| 47 | 'question' => 'answer', |
||
| 48 | ], |
||
| 49 | ], |
||
| 50 | ]); |
||
| 51 | |||
| 52 | $index->setMapping($mapping); |
||
| 53 | |||
| 54 | $expected = [ |
||
| 55 | 'properties' => [ |
||
| 56 | 'firstname' => ['type' => 'text', 'store' => true], |
||
| 57 | 'lastname' => ['type' => 'text'], |
||
| 58 | 'my_join_field' => [ |
||
| 59 | 'type' => 'join', |
||
| 60 | 'relations' => [ |
||
| 61 | 'question' => 'answer', |
||
| 62 | ], |
||
| 63 | ], |
||
| 64 | ], |
||
| 65 | ]; |
||
| 66 | |||
| 67 | $this->assertEquals($expected, $mapping->toArray()); |
||
| 68 | $index->refresh(); |
||
| 69 | |||
| 70 | $doc1 = $index->createDocument('1', [ |
||
| 71 | 'text' => 'this is the 1st question', |
||
| 72 | 'my_join_field' => [ |
||
| 73 | 'name' => 'question', |
||
| 74 | ], |
||
| 75 | ]); |
||
| 76 | $doc2 = $index->createDocument('2', [ |
||
| 77 | 'text' => 'this is the 2nd question', |
||
| 78 | 'my_join_field' => [ |
||
| 79 | 'name' => 'question', |
||
| 80 | ], |
||
| 81 | ]); |
||
| 82 | $index->addDocuments([$doc1, $doc2]); |
||
| 83 | |||
| 84 | $doc3 = $index->createDocument('3', [ |
||
| 85 | 'text' => 'this is an answer, the 1st', |
||
| 86 | 'my_join_field' => [ |
||
| 87 | 'name' => 'answer', |
||
| 88 | 'parent' => 1, |
||
| 89 | ], |
||
| 90 | ]); |
||
| 91 | $doc4 = $index->createDocument('4', [ |
||
| 92 | 'text' => 'this is an answer, the 2nd', |
||
| 93 | 'my_join_field' => [ |
||
| 94 | 'name' => 'answer', |
||
| 95 | 'parent' => '2', |
||
| 96 | ], |
||
| 97 | ]); |
||
| 98 | $doc5 = $index->createDocument('5', [ |
||
| 99 | 'text' => 'this is an answer, the 3rd', |
||
| 100 | 'my_join_field' => [ |
||
| 101 | 'name' => 'answer', |
||
| 102 | 'parent' => '2', |
||
| 103 | ], |
||
| 104 | ]); |
||
| 105 | $this->_getClient()->addDocuments([$doc3, $doc4, $doc5], ['routing' => 1]); |
||
| 106 | $index->refresh(); |
||
| 107 | |||
| 108 | $parentQuery = new ParentId('answer', 1, true); |
||
| 109 | $search = new Search($index->getClient()); |
||
| 110 | $results = $search->search($parentQuery); |
||
| 111 | $this->assertEquals(1, $results->count()); |
||
| 112 | |||
| 113 | $result = $results->current(); |
||
| 114 | $data = $result->getData(); |
||
| 115 | $this->assertEquals($data['text'], 'this is an answer, the 1st'); |
||
| 116 | |||
| 117 | $parentQuery = new ParentId('answer', '2', true); |
||
| 118 | $search = new Search($index->getClient()); |
||
| 119 | $results = $search->search($parentQuery); |
||
| 120 | $this->assertEquals(2, $results->count()); |
||
| 121 | } |
||
| 122 | |||
| 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: