| Conditions | 16 |
| Paths | 580 |
| Total Lines | 90 |
| Code Lines | 49 |
| 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 |
||
| 60 | public function show($collection, $interval = 'count', $timeframe = null, $filters = null) |
||
| 61 | { |
||
| 62 | $start = $timeframe ? array_get($timeframe, 'start') : null; |
||
| 63 | $end = $timeframe ? array_get($timeframe, 'end') : null; |
||
| 64 | $matchArray = []; |
||
| 65 | $filters = json_decode($filters); |
||
| 66 | $intervalFormat = '%Y-%m-%dT%H'; |
||
| 67 | $aggregate = []; |
||
| 68 | |||
| 69 | $model = $this->namespace.studly_case(str_singular($collection)).'Analytic'; |
||
| 70 | |||
| 71 | if (! class_exists($model)) { |
||
| 72 | throw new InvalidArgumentException("Model {$model} does not exist."); |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($filters) { |
||
| 76 | foreach ($filters as $filter) { |
||
| 77 | $propertyValue = $filter->property_value; |
||
| 78 | |||
| 79 | if (is_numeric($propertyValue)) { |
||
| 80 | $propertyValue = (int) $propertyValue; |
||
| 81 | } |
||
| 82 | |||
| 83 | $matchArray = array_merge($matchArray, [$filter->property_name => $propertyValue]); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | abort_unless($this->canViewAnalytic($matchArray, auth()->user()), 403, 'You dont have permission to view these analytics'); |
||
| 88 | |||
| 89 | if ($start) { |
||
| 90 | $matchArray['created_at']['$gte'] = mongoTime($start); |
||
| 91 | } |
||
| 92 | |||
| 93 | if ($end) { |
||
| 94 | $matchArray['created_at']['$lt'] = mongoTime($end); |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($matchArray) { |
||
| 98 | $aggregate[] = ['$match' => $matchArray]; |
||
| 99 | } |
||
| 100 | |||
| 101 | if ($interval != 'count') { |
||
| 102 | if ($interval == 'daily') { |
||
| 103 | $intervalFormat = '%Y-%m-%d'; |
||
| 104 | } |
||
| 105 | |||
| 106 | if ($interval == 'weekly') { |
||
| 107 | $intervalFormat = '%Y-%U'; |
||
| 108 | } |
||
| 109 | |||
| 110 | if ($interval == 'monthly') { |
||
| 111 | $intervalFormat = '%Y-%m'; |
||
| 112 | } |
||
| 113 | |||
| 114 | $aggregate[] = [ |
||
| 115 | '$group' => [ |
||
| 116 | '_id' => [ |
||
| 117 | '$dateToString' => ['date' => '$created_at', 'format' => $intervalFormat], |
||
| 118 | ], |
||
| 119 | 'count' => [ |
||
| 120 | '$sum' => 1, |
||
| 121 | ], |
||
| 122 | 'created_at' => [ |
||
| 123 | '$first' => '$created_at', |
||
| 124 | ], |
||
| 125 | ], |
||
| 126 | ]; |
||
| 127 | |||
| 128 | $aggregate[] = ['$sort' => ['created_at' => 1]]; |
||
| 129 | |||
| 130 | $aggregate[] = [ |
||
| 131 | '$project' => [ |
||
| 132 | '_id' => 0, |
||
| 133 | 'created_at' => 1, |
||
| 134 | 'count' => 1, |
||
| 135 | ], |
||
| 136 | ]; |
||
| 137 | } |
||
| 138 | |||
| 139 | $data = $model::raw(function ($collection) use ($matchArray, $interval, $aggregate) { |
||
| 140 | if ($interval == 'count') { |
||
| 141 | return $collection->count($matchArray); |
||
| 142 | } |
||
| 143 | |||
| 144 | if ($aggregate) { |
||
| 145 | return $collection->aggregate($aggregate, ['allowDiskUse' => true]); |
||
| 146 | } |
||
| 147 | }); |
||
| 148 | |||
| 149 | return $data; |
||
| 150 | } |
||
| 220 |
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