Conditions | 4 |
Paths | 4 |
Total Lines | 69 |
Code Lines | 44 |
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 |
||
68 | public function search($searchTerm) |
||
69 | { |
||
70 | if ('' === $this->getLanguage()) { |
||
71 | $searchParams = [ |
||
72 | 'index' => $this->esConfig['index'], |
||
73 | 'type' => $this->esConfig['type'], |
||
74 | 'size' => 1000, |
||
75 | 'body' => [ |
||
76 | 'query' => [ |
||
77 | 'bool' => [ |
||
78 | 'should' => [ |
||
79 | [ 'match' => [ 'question' => $searchTerm ] ], |
||
80 | [ 'match' => [ 'answer' => $searchTerm ] ], |
||
81 | [ 'match' => [ 'keywords' => $searchTerm ] ] |
||
82 | ] |
||
83 | ] |
||
84 | |||
85 | ] |
||
86 | ] |
||
87 | ]; |
||
88 | } else { |
||
89 | $searchParams = [ |
||
90 | 'index' => $this->esConfig['index'], |
||
91 | 'type' => $this->esConfig['type'], |
||
92 | 'size' => 1000, |
||
93 | 'body' => [ |
||
94 | 'query' => [ |
||
95 | 'filtered' => [ |
||
96 | 'filter' => [ |
||
97 | 'term' => [ 'lang' => $this->getLanguage() ] |
||
98 | ], |
||
99 | 'query' => [ |
||
100 | 'bool' => [ |
||
101 | 'should' => [ |
||
102 | [ 'match' => [ 'question' => $searchTerm ] ], |
||
103 | [ 'match' => [ 'answer' => $searchTerm ] ], |
||
104 | [ 'match' => [ 'keywords' => $searchTerm ] ] |
||
105 | ] |
||
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 | |||
154 |
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..