1 | <?php namespace Arcanedev\LaravelMetrics\Metrics; |
||
16 | abstract class Trend extends Metric |
||
17 | { |
||
18 | /* ----------------------------------------------------------------- |
||
19 | | Constants |
||
20 | | ----------------------------------------------------------------- |
||
21 | */ |
||
22 | |||
23 | /** |
||
24 | * Trend metric unit constants. |
||
25 | */ |
||
26 | const BY_MONTHS = 'month'; |
||
27 | const BY_WEEKS = 'week'; |
||
28 | const BY_DAYS = 'day'; |
||
29 | const BY_HOURS = 'hour'; |
||
30 | const BY_MINUTES = 'minute'; |
||
31 | |||
32 | /* ----------------------------------------------------------------- |
||
33 | | Traits |
||
34 | | ----------------------------------------------------------------- |
||
35 | */ |
||
36 | |||
37 | use Concerns\AggregatesTrends, |
||
38 | Concerns\HasExpressions, |
||
39 | Concerns\HasRanges, |
||
40 | Concerns\FormatsTrends; |
||
41 | |||
42 | /* ----------------------------------------------------------------- |
||
43 | | Getters |
||
44 | | ----------------------------------------------------------------- |
||
45 | */ |
||
46 | |||
47 | /** |
||
48 | * Get the metric type. |
||
49 | * |
||
50 | * @return string |
||
51 | */ |
||
52 | 12 | public function type(): string |
|
56 | |||
57 | /* ----------------------------------------------------------------- |
||
58 | | Main Methods |
||
59 | | ----------------------------------------------------------------- |
||
60 | */ |
||
61 | |||
62 | /** |
||
63 | * Calculate the `count` of the metric. |
||
64 | * |
||
65 | * @param string $unit |
||
66 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
67 | * @param string|null $dateColumn |
||
68 | * @param string|null $column |
||
69 | * |
||
70 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
71 | */ |
||
72 | 12 | public function count($unit, $model, $dateColumn = null, $column = null) |
|
76 | |||
77 | /** |
||
78 | * Return a value result showing a average aggregate over time. |
||
79 | * |
||
80 | * @param string $unit |
||
81 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
82 | * @param string $column |
||
83 | * @param string|null $dateColumn |
||
84 | * |
||
85 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
86 | */ |
||
87 | public function average(string $unit, $model, $column, $dateColumn = null) |
||
91 | |||
92 | /** |
||
93 | * Return a value result showing a sum aggregate over time. |
||
94 | * |
||
95 | * @param string $unit |
||
96 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
97 | * @param string $column |
||
98 | * @param string|null $dateColumn |
||
99 | * |
||
100 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
101 | */ |
||
102 | public function sum(string $unit, $model, $column, $dateColumn = null) |
||
106 | |||
107 | /** |
||
108 | * Return a value result showing a max aggregate over time. |
||
109 | * |
||
110 | * @param string $unit |
||
111 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
112 | * @param string $column |
||
113 | * @param string|null $dateColumn |
||
114 | * |
||
115 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
116 | */ |
||
117 | public function max(string $unit, $model, $column, $dateColumn = null) |
||
121 | |||
122 | /** |
||
123 | * Return a value result showing a min aggregate over time. |
||
124 | * |
||
125 | * @param string $unit |
||
126 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
127 | * @param string $column |
||
128 | * @param string|null $dateColumn |
||
129 | * |
||
130 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
131 | */ |
||
132 | public function min(string $unit, $model, $column, $dateColumn = null) |
||
136 | |||
137 | /** |
||
138 | * Make a new result instance. |
||
139 | * |
||
140 | * @param mixed|null $value |
||
141 | * |
||
142 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
143 | */ |
||
144 | 12 | protected function result($value = null) |
|
148 | |||
149 | /* ----------------------------------------------------------------- |
||
150 | | Other Methods |
||
151 | | ----------------------------------------------------------------- |
||
152 | */ |
||
153 | |||
154 | /** |
||
155 | * Handle the aggregate calculation of the metric. |
||
156 | * |
||
157 | * @param string $method |
||
158 | * @param string $unit |
||
159 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
160 | * @param string|null $column |
||
161 | * @param string|null $dateColumn |
||
162 | * |
||
163 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
164 | */ |
||
165 | 12 | protected function aggregate(string $method, string $unit, $model, ?string $column = null, ?string $dateColumn = null) |
|
219 | |||
220 | /** |
||
221 | * Parse the date result. |
||
222 | * |
||
223 | * @param string $date |
||
224 | * @param string $unit |
||
225 | * |
||
226 | * @return \Cake\Chronos\Chronos |
||
227 | */ |
||
228 | 12 | protected function parseDateResult(string $date, string $unit): Chronos |
|
251 | |||
252 | /** |
||
253 | * Determine the proper aggregate starting date. |
||
254 | * |
||
255 | * @param string $unit |
||
256 | * @param mixed|null $range |
||
257 | * |
||
258 | * @return \Cake\Chronos\Chronos |
||
259 | */ |
||
260 | 12 | protected static function getAggregateStartingDate(string $unit, $range = null): Chronos |
|
288 | |||
289 | /** |
||
290 | * Prepare the metric for JSON serialization. |
||
291 | * |
||
292 | * @return array |
||
293 | */ |
||
294 | public function toArray(): array |
||
301 | } |
||
302 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: