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