Conditions | 12 |
Paths | 8 |
Total Lines | 114 |
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 |
||
123 | protected function parseInputsKeywordConstraints($query){ |
||
124 | |||
125 | //Aplicación del los where's de los atributos searchable propios del Modelo. |
||
126 | |||
127 | $searchableModelInputs = $this->parseModelInputs($this->searchableInputsKeyword); |
||
128 | |||
129 | $query = $query->where(function($query) use ($searchableModelInputs){ |
||
130 | |||
131 | // Aplicación de los where's en las columnas propias del Modelo. |
||
132 | |||
133 | $query = $query->where(function($query) use ($searchableModelInputs){ |
||
134 | |||
135 | foreach ($searchableModelInputs as $attribute) { |
||
136 | |||
137 | $value = Arr::get($this->searchableInputsKeyword, $attribute, $this->searchableKeyword); |
||
138 | |||
139 | if ($value) { |
||
140 | |||
141 | $query->orWhere($attribute, 'LIKE', "%{$value}") |
||
142 | ->orWhere($attribute, 'LIKE', "{$value}%") |
||
143 | ->orWhere($attribute, 'LIKE', "%{$value}%"); |
||
144 | } |
||
145 | } |
||
146 | }); |
||
147 | |||
148 | // Aplicación de los where's de las relaciones del Modelo que cuyo valor es el del 'keyword'. |
||
149 | |||
150 | if ($this->searchableKeyword) { |
||
151 | |||
152 | $searchableRelationInputs = $this->parseRelationInputs($this->searchableInputsKeyword); |
||
153 | |||
154 | $searchableRelation = $this->parseRelationInputs($this->searchableInputs); |
||
155 | |||
156 | foreach ($searchableRelationInputs as $attribute => $columns) { |
||
157 | |||
158 | if (!in_array($attribute, array_keys($searchableRelation))) { |
||
159 | |||
160 | $query->orWhereHas($attribute, function ($query) use ($attribute, $searchableRelationInputs) { |
||
161 | |||
162 | $query = $query->where(function($query) use ($attribute, $searchableRelationInputs){ |
||
163 | |||
164 | $columns = $searchableRelationInputs[$attribute] ?? []; |
||
165 | |||
166 | foreach ($columns as $column) { |
||
167 | |||
168 | $value = $this->searchableInputsKeyword["{$attribute}:{$column}"] ?? $this->searchableKeyword; |
||
169 | |||
170 | $query->orWhere($column, 'LIKE', "%{$value}") |
||
171 | ->orWhere($column, 'LIKE', "{$value}%") |
||
172 | ->orWhere($column, 'LIKE', "%{$value}%"); |
||
173 | } |
||
174 | }); |
||
175 | }); |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | }); |
||
180 | |||
181 | // Aplicación del los where's de los atributos filterable propios del Modelo. |
||
182 | |||
183 | $filterableModelInputs = $this->parseModelInputs($this->filterableInputs); |
||
184 | |||
185 | $filterableModelInputs = Arr::only($this->filterableInputs, $filterableModelInputs); |
||
186 | |||
187 | foreach ($filterableModelInputs as $column => $value) { |
||
188 | |||
189 | $query->where($column, '=', str_trimmer($value)); |
||
190 | } |
||
191 | |||
192 | // Se añade los constraints para las relaciones definidads en el searchable del Modelo. |
||
193 | |||
194 | $searchableRelationInputs = $this->parseRelationInputs($this->searchableInputs); |
||
195 | |||
196 | foreach ($searchableRelationInputs as $attribute => $columns) { |
||
197 | |||
198 | $this->addRelationConstraints([$attribute => function ($query) use ($attribute, $searchableRelationInputs) { |
||
199 | |||
200 | $columns = $searchableRelationInputs[$attribute] ?? []; |
||
201 | |||
202 | foreach ($columns as $column) { |
||
203 | |||
204 | $value = Arr::get($this->searchableInputs, "{$attribute}:{$column}"); |
||
205 | |||
206 | $query->where(function($query) use ($column, $value){ |
||
207 | |||
208 | $query->orWhere($column, 'LIKE', "%{$value}") |
||
209 | ->orWhere($column, 'LIKE', "{$value}%") |
||
210 | ->orWhere($column, 'LIKE', "%{$value}%"); |
||
211 | }); |
||
212 | } |
||
213 | }]); |
||
214 | } |
||
215 | |||
216 | // Se añade los constraints de las relaciones definidads en el filterable del Modelo. |
||
217 | |||
218 | $filterableRelationInputs = $this->parseRelationInputs($this->filterableInputs); |
||
219 | |||
220 | foreach ($filterableRelationInputs as $attribute => $columns) { |
||
221 | |||
222 | $this->addRelationConstraints([$attribute => function ($query) use ($attribute, $filterableRelationInputs) { |
||
223 | |||
224 | $columns = $filterableRelationInputs[$attribute] ?? []; |
||
225 | |||
226 | foreach ($columns as $column) { |
||
227 | |||
228 | $value = Arr::get($this->filterableInputs, "{$attribute}:{$column}"); |
||
229 | |||
230 | $query->where($column, '=', str_trimmer($value)); |
||
231 | } |
||
232 | }]); |
||
233 | } |
||
234 | |||
235 | return $query; |
||
236 | } |
||
237 | |||
378 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.