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