| Conditions | 10 |
| Paths | 8 |
| Total Lines | 43 |
| Code Lines | 31 |
| 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 |
||
| 46 | public function toSearchableArray() |
||
| 47 | { |
||
| 48 | if (!sizeof($this->searchableColumns)) { |
||
| 49 | $result = collect($this); |
||
| 50 | } else { |
||
| 51 | $result = collect([ |
||
| 52 | 'id' => $this['id'], |
||
| 53 | ]); |
||
| 54 | foreach ($this->searchableColumns as $searchableColumn) { |
||
| 55 | $result->put($searchableColumn, collect($this)->get($searchableColumn)); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | if (sizeof($this->searchableInnerColumns)) { |
||
| 59 | foreach ($this->searchableInnerColumns as $searchableInnerColumnKey => $searchableInnerColumnValue) { |
||
| 60 | $searchableInnerColumnKey = explode('-', $searchableInnerColumnKey)[0]; |
||
| 61 | $innerModels = explode('.', $searchableInnerColumnKey); |
||
| 62 | $values = $this; |
||
| 63 | foreach ($innerModels as $innerModel) { |
||
| 64 | $values = $values->{$innerModel}; |
||
| 65 | } |
||
| 66 | $values = collect($values); |
||
| 67 | $result->put($searchableInnerColumnKey . '-' . $searchableInnerColumnValue, |
||
| 68 | collect($values)->get($searchableInnerColumnValue)); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | if (sizeof($this->searchableManyInnerColumns)) { |
||
| 72 | foreach ($this->searchableManyInnerColumns as $searchableInnerColumnKey => $searchableInnerColumnValue) { |
||
| 73 | $searchableInnerColumnKey = explode('-', $searchableInnerColumnKey)[0]; |
||
| 74 | $innerModels = explode('.', $searchableInnerColumnKey); |
||
| 75 | $values = $this; |
||
| 76 | foreach ($innerModels as $innerModel) { |
||
| 77 | $values = $values->{$innerModel}; |
||
| 78 | } |
||
| 79 | $values = collect($values); |
||
| 80 | $counter = 0; |
||
| 81 | foreach ($values as $value) { |
||
| 82 | $result->put($searchableInnerColumnKey . '-' . $searchableInnerColumnValue . '-' . $counter, |
||
| 83 | collect($value)->get($searchableInnerColumnValue)); |
||
| 84 | $counter++; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | return $result->toArray(); |
||
| 89 | } |
||
| 125 |
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.