Conditions | 4 |
Paths | 4 |
Total Lines | 66 |
Code Lines | 40 |
Lines | 0 |
Ratio | 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 |
||
71 | public function search($searchTerm) |
||
72 | { |
||
73 | if ('' !== $this->getLanguage()) { |
||
74 | $languageFilter = [ |
||
75 | 'term' => [ |
||
76 | 'lang' => $this->getLanguage() |
||
77 | ] |
||
78 | ]; |
||
79 | } else { |
||
80 | $languageFilter = ''; |
||
81 | } |
||
82 | |||
83 | $searchParams = [ |
||
84 | 'index' => $this->esConfig['index'], |
||
85 | 'type' => $this->esConfig['type'], |
||
86 | 'size' => 1000, |
||
87 | 'body' => [ |
||
88 | 'query' => [ |
||
89 | 'filtered' => [ |
||
90 | 'filter' => [ |
||
91 | 'bool' => [ |
||
92 | 'must' => [ |
||
93 | [ |
||
94 | 'terms' => [ 'category_id' => $this->getCategoryIds() ] |
||
95 | ], |
||
96 | $languageFilter |
||
97 | ] |
||
98 | ] |
||
99 | ], |
||
100 | 'query' => [ |
||
101 | 'bool' => [ |
||
102 | 'should' => [ |
||
103 | [ 'match' => [ 'question' => $searchTerm ] ], |
||
104 | [ 'match' => [ 'answer' => $searchTerm ] ], |
||
105 | [ 'match' => [ 'keywords' => $searchTerm ] ] |
||
106 | ] |
||
107 | ] |
||
108 | ] |
||
109 | ] |
||
110 | ] |
||
111 | ] |
||
112 | ]; |
||
113 | |||
114 | $result = $this->client->search($searchParams); |
||
115 | |||
116 | if (0 !== $result['hits']['total']) { |
||
117 | |||
118 | foreach ($result['hits']['hits'] as $hit) { |
||
119 | $resultSet = new stdClass(); |
||
120 | $resultSet->id = $hit['_source']['id']; |
||
121 | $resultSet->lang = $hit['_source']['lang']; |
||
122 | $resultSet->question = $hit['_source']['question']; |
||
123 | $resultSet->answer = $hit['_source']['answer']; |
||
124 | $resultSet->keywords = $hit['_source']['keywords']; |
||
125 | $resultSet->category_id = $hit['_source']['category_id']; |
||
126 | $resultSet->score = $hit['_score']; |
||
127 | |||
128 | $this->resultSet[] = $resultSet; |
||
129 | } |
||
130 | |||
131 | } else { |
||
132 | $this->resultSet = []; |
||
|
|||
133 | } |
||
134 | |||
135 | return $this->resultSet; |
||
136 | } |
||
137 | |||
193 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..