| Conditions | 7 |
| Paths | 6 |
| Total Lines | 20 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | public function scopeFilter($query, array $filterData = []) |
||
| 10 | { |
||
| 11 | foreach ($filterData as $key => $value) { |
||
| 12 | if (!$this->isFilterable($key)) { |
||
| 13 | throw new FilterableException("[$key] is not allowed for filtering"); |
||
| 14 | } |
||
| 15 | |||
| 16 | if (is_null($value) || $value === '') continue; |
||
| 17 | |||
| 18 | $scopeName = ucfirst(camel_case($key)); |
||
| 19 | |||
| 20 | if (method_exists($this, 'scope' . $scopeName)) { |
||
| 21 | $query->$scopeName($value); |
||
| 22 | } else if (is_array($value)) { |
||
| 23 | $query->whereIn($key, $value); |
||
| 24 | } else { |
||
| 25 | $query->where($key, $value); |
||
| 26 | } |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 36 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: