| Conditions | 8 |
| Paths | 1 |
| Total Lines | 65 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 | $this->loadTranslationsFrom( |
||
| 13 | __DIR__.'/../lang', |
||
| 14 | 'query-builder' |
||
| 15 | ); |
||
| 16 | |||
| 17 | $this->publishes([ |
||
| 18 | __DIR__.'/../lang' => resource_path('lang/vendor/query-builder'), |
||
| 19 | ]); |
||
| 20 | |||
| 21 | Request::macro('includes', function ($include = null) { |
||
| 22 | $includeParts = $this->query('include'); |
||
|
|
|||
| 23 | |||
| 24 | if (! is_array($includeParts)) { |
||
| 25 | $includeParts = explode(',', strtolower($this->query('include'))); |
||
| 26 | } |
||
| 27 | |||
| 28 | $includes = collect($includeParts)->filter(); |
||
| 29 | |||
| 30 | if (is_null($include)) { |
||
| 31 | return $includes; |
||
| 32 | } |
||
| 33 | |||
| 34 | return $includes->contains(strtolower($include)); |
||
| 35 | }); |
||
| 36 | |||
| 37 | Request::macro('filters', function ($filter = null) { |
||
| 38 | $filterParts = $this->query('filter'); |
||
| 39 | |||
| 40 | if (! $filterParts) { |
||
| 41 | return collect(); |
||
| 42 | } |
||
| 43 | |||
| 44 | $filters = collect($filterParts)->filter(function ($filter) { |
||
| 45 | return ! is_null($filter); |
||
| 46 | }); |
||
| 47 | |||
| 48 | $filters = $filters->map(function ($value) { |
||
| 49 | if (str_contains($value, ',')) { |
||
| 50 | return explode(',', $value); |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($value === 'true') { |
||
| 54 | return true; |
||
| 55 | } |
||
| 56 | |||
| 57 | if ($value === 'false') { |
||
| 58 | return false; |
||
| 59 | } |
||
| 60 | |||
| 61 | return $value; |
||
| 62 | }); |
||
| 63 | |||
| 64 | if (is_null($filter)) { |
||
| 65 | return $filters; |
||
| 66 | } |
||
| 67 | |||
| 68 | return $filters->get(strtolower($filter)); |
||
| 69 | }); |
||
| 70 | |||
| 71 | Request::macro('sort', function ($default = null) { |
||
| 72 | return $this->query('sort', $default); |
||
| 73 | }); |
||
| 74 | } |
||
| 75 | } |
||
| 76 |
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.