| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 74 | 
| 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  | 
            ||
| 90 | public function testScriptFieldWithJoin(): void  | 
            ||
| 91 |     { | 
            ||
| 92 | $client = $this->_getClient();  | 
            ||
| 93 |         $index = $client->getIndex('testscriptfieldwithjoin'); | 
            ||
| 94 | $index->create([], true);  | 
            ||
| 95 | |||
| 96 | $mapping = new Mapping([  | 
            ||
| 97 | 'text' => ['type' => 'keyword'],  | 
            ||
| 98 | 'name' => ['type' => 'keyword'],  | 
            ||
| 99 | 'my_join_field' => [  | 
            ||
| 100 | 'type' => 'join',  | 
            ||
| 101 | 'relations' => [  | 
            ||
| 102 | 'question' => 'answer',  | 
            ||
| 103 | ],  | 
            ||
| 104 | ],  | 
            ||
| 105 | ]);  | 
            ||
| 106 | |||
| 107 | $index->setMapping($mapping);  | 
            ||
| 108 | $index->refresh();  | 
            ||
| 109 | |||
| 110 | $doc1 = $index->createDocument(1, [  | 
            ||
| 111 | 'text' => 'this is the 1st question',  | 
            ||
| 112 | 'my_join_field' => [  | 
            ||
| 113 | 'name' => 'question',  | 
            ||
| 114 | ],  | 
            ||
| 115 | ]);  | 
            ||
| 116 | $doc2 = $index->createDocument(2, [  | 
            ||
| 117 | 'text' => 'this is the 2nd question',  | 
            ||
| 118 | 'my_join_field' => [  | 
            ||
| 119 | 'name' => 'question',  | 
            ||
| 120 | ],  | 
            ||
| 121 | ]);  | 
            ||
| 122 | $index->addDocuments([$doc1, $doc2]);  | 
            ||
| 123 | |||
| 124 | $doc3 = $index->createDocument(3, [  | 
            ||
| 125 | 'text' => 'this is an answer, the 1st',  | 
            ||
| 126 | 'name' => 'rico',  | 
            ||
| 127 | 'my_join_field' => [  | 
            ||
| 128 | 'name' => 'answer',  | 
            ||
| 129 | 'parent' => 1,  | 
            ||
| 130 | ],  | 
            ||
| 131 | ]);  | 
            ||
| 132 | $doc4 = $index->createDocument(4, [  | 
            ||
| 133 | 'text' => 'this is an answer, the 2nd',  | 
            ||
| 134 | 'name' => 'fede',  | 
            ||
| 135 | 'my_join_field' => [  | 
            ||
| 136 | 'name' => 'answer',  | 
            ||
| 137 | 'parent' => 2,  | 
            ||
| 138 | ],  | 
            ||
| 139 | ]);  | 
            ||
| 140 | $doc5 = $index->createDocument(5, [  | 
            ||
| 141 | 'text' => 'this is an answer, the 3rd',  | 
            ||
| 142 | 'name' => 'fede',  | 
            ||
| 143 | 'my_join_field' => [  | 
            ||
| 144 | 'name' => 'answer',  | 
            ||
| 145 | 'parent' => 2,  | 
            ||
| 146 | ],  | 
            ||
| 147 | ]);  | 
            ||
| 148 | |||
| 149 | $this->_getClient()->addDocuments([$doc3, $doc4, $doc5], ['routing' => 1]);  | 
            ||
| 150 | $index->refresh();  | 
            ||
| 151 | |||
| 152 | $query = new Query();  | 
            ||
| 153 |         $script = new Script("doc['my_join_field#question']"); | 
            ||
| 154 | $scriptFields = new ScriptFields([  | 
            ||
| 155 | 'text' => $script,  | 
            ||
| 156 | ]);  | 
            ||
| 157 | $query->setScriptFields($scriptFields);  | 
            ||
| 158 | $resultSet = $index->search($query);  | 
            ||
| 159 | $results = $resultSet->getResults();  | 
            ||
| 160 | |||
| 161 | $this->assertEquals(1, ($results[0]->getHit())['fields']['text'][0]);  | 
            ||
| 162 | $this->assertEquals(2, ($results[1]->getHit())['fields']['text'][0]);  | 
            ||
| 163 | }  | 
            ||
| 164 | }  | 
            ||
| 165 |