| Conditions | 13 |
| Paths | 132 |
| Total Lines | 74 |
| Code Lines | 35 |
| 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 |
||
| 54 | public function show($collection, $interval = 'count', $timeframe = null, $filters = null) |
||
| 55 | { |
||
| 56 | $start = $timeframe ? array_get($timeframe, 'start') : null; |
||
| 57 | $end = $timeframe ? array_get($timeframe, 'end') : null; |
||
| 58 | $matchArray = []; |
||
| 59 | $filters = json_decode($filters); |
||
| 60 | |||
| 61 | $model = $this->namespace.studly_case(str_singular($collection)).'Analytic'; |
||
| 62 | |||
| 63 | if (! class_exists($model)) { |
||
| 64 | throw new InvalidArgumentException("Model {$model} does not exist."); |
||
| 65 | } |
||
| 66 | |||
| 67 | if ($filters) { |
||
| 68 | foreach ($filters as $filter) { |
||
| 69 | $propertyValue = $filter->property_value; |
||
| 70 | |||
| 71 | if (is_numeric($propertyValue)) { |
||
| 72 | $propertyValue = (int) $propertyValue; |
||
| 73 | } |
||
| 74 | |||
| 75 | $matchArray = array_merge($matchArray, [$filter->property_name => $propertyValue]); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | abort_unless($this->canViewAnalytic($matchArray, auth()->user()), 403, 'You dont have permission to view these analytics'); |
||
| 80 | |||
| 81 | if ($start) { |
||
| 82 | $matchArray['created_at']['$gte'] = mongoTime($start); |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($end) { |
||
| 86 | $matchArray['created_at']['$lt'] = mongoTime($end); |
||
| 87 | } |
||
| 88 | |||
| 89 | $aggregate = []; |
||
| 90 | |||
| 91 | if ($matchArray) { |
||
| 92 | $aggregate[] = ['$match' => $matchArray]; |
||
| 93 | } |
||
| 94 | |||
| 95 | $aggregate[] = ['$sort' => ['created_at' => 1]]; |
||
| 96 | |||
| 97 | $aggregate[] = [ |
||
| 98 | '$project' => [ |
||
| 99 | 'created_at' => 1 |
||
| 100 | ], |
||
| 101 | ]; |
||
| 102 | |||
| 103 | //$aggregate[] = ['$batchSize' => 1000]; |
||
| 104 | |||
| 105 | // $data = DB::connection($this->connection) |
||
| 106 | // ->collection($collection) |
||
| 107 | // ->raw(function ($query) use ($aggregate) { |
||
| 108 | // return $query->aggregate($aggregate); |
||
| 109 | // }); |
||
| 110 | |||
| 111 | $data = DB::connection($this->connection) |
||
| 112 | ->collection($collection) |
||
| 113 | ->raw(function ($collection) use ($matchArray, $interval, $aggregate) { |
||
| 114 | if ($interval == 'count') { |
||
| 115 | return $collection->count($matchArray); |
||
| 116 | } |
||
| 117 | |||
| 118 | if ($aggregate) { |
||
| 119 | return $collection->aggregate($aggregate, ['allowDiskUse' => true]); |
||
| 120 | } |
||
| 121 | }); |
||
| 122 | |||
| 123 | if ($interval != 'count') { |
||
| 124 | $data = $this->toModels($data, $model); |
||
| 125 | } |
||
| 126 | |||
| 127 | return $data; |
||
| 128 | } |
||
| 199 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths