| Conditions | 10 |
| Paths | 1 |
| Total Lines | 72 |
| Code Lines | 36 |
| 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 |
||
| 10 | public function boot() |
||
| 11 | { |
||
| 12 | Request::macro('includes', function ($include = null) { |
||
| 13 | $includeParts = $this->query('include'); |
||
|
|
|||
| 14 | |||
| 15 | if (! is_array($includeParts)) { |
||
| 16 | $includeParts = explode(',', strtolower($this->query('include'))); |
||
| 17 | } |
||
| 18 | |||
| 19 | $includes = collect($includeParts)->filter(); |
||
| 20 | |||
| 21 | if (is_null($include)) { |
||
| 22 | return $includes; |
||
| 23 | } |
||
| 24 | |||
| 25 | return $includes->contains(strtolower($include)); |
||
| 26 | }); |
||
| 27 | |||
| 28 | Request::macro('filters', function ($filter = null) { |
||
| 29 | $filterParts = $this->query('filter'); |
||
| 30 | |||
| 31 | if (! $filterParts) { |
||
| 32 | return collect(); |
||
| 33 | } |
||
| 34 | |||
| 35 | $filters = collect($filterParts)->filter(function ($filter) { |
||
| 36 | return ! is_null($filter); |
||
| 37 | }); |
||
| 38 | |||
| 39 | $filters = $filters->map(function ($value) { |
||
| 40 | if (str_contains($value, ',')) { |
||
| 41 | return explode(',', $value); |
||
| 42 | } |
||
| 43 | |||
| 44 | if ($value === 'true') { |
||
| 45 | return true; |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($value === 'false') { |
||
| 49 | return false; |
||
| 50 | } |
||
| 51 | |||
| 52 | return $value; |
||
| 53 | }); |
||
| 54 | |||
| 55 | if (is_null($filter)) { |
||
| 56 | return $filters; |
||
| 57 | } |
||
| 58 | |||
| 59 | return $filters->get(strtolower($filter)); |
||
| 60 | }); |
||
| 61 | |||
| 62 | Request::macro('sort', function ($default = null) { |
||
| 63 | return $this->query('sort', $default); |
||
| 64 | }); |
||
| 65 | |||
| 66 | Request::macro('sorts', function ($default = null) { |
||
| 67 | $sortParts = $this->sort(); |
||
| 68 | |||
| 69 | if (! is_array($sortParts)) { |
||
| 70 | $sortParts = explode(',', $sortParts); |
||
| 71 | } |
||
| 72 | |||
| 73 | $sorts = collect($sortParts)->filter(); |
||
| 74 | |||
| 75 | if ($sorts->isNotEmpty()) { |
||
| 76 | return $sorts; |
||
| 77 | } |
||
| 78 | |||
| 79 | return collect($default)->filter(); |
||
| 80 | }); |
||
| 81 | } |
||
| 82 | } |
||
| 83 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.