1 | <?php |
||
19 | abstract class Trend extends Metric |
||
20 | { |
||
21 | /* ----------------------------------------------------------------- |
||
22 | | Constants |
||
23 | | ----------------------------------------------------------------- |
||
24 | */ |
||
25 | |||
26 | /** |
||
27 | * Trend metric unit constants. |
||
28 | */ |
||
29 | const BY_MONTHS = 'month'; |
||
30 | const BY_WEEKS = 'week'; |
||
31 | const BY_DAYS = 'day'; |
||
32 | const BY_HOURS = 'hour'; |
||
33 | const BY_MINUTES = 'minute'; |
||
34 | |||
35 | /* ----------------------------------------------------------------- |
||
36 | | Traits |
||
37 | | ----------------------------------------------------------------- |
||
38 | */ |
||
39 | |||
40 | use Concerns\AggregatesTrends, |
||
41 | Concerns\HasExpressions, |
||
42 | Concerns\HasRanges, |
||
43 | Concerns\HasRoundedValue, |
||
44 | Concerns\FormatsTrends; |
||
45 | |||
46 | /* ----------------------------------------------------------------- |
||
47 | | Getters |
||
48 | | ----------------------------------------------------------------- |
||
49 | */ |
||
50 | |||
51 | /** |
||
52 | * Get the metric type. |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | 36 | public function type(): string |
|
60 | |||
61 | /* ----------------------------------------------------------------- |
||
62 | | Main Methods |
||
63 | | ----------------------------------------------------------------- |
||
64 | */ |
||
65 | |||
66 | /** |
||
67 | * Calculate the `count` of the metric. |
||
68 | * |
||
69 | * @param string $unit |
||
70 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
71 | * @param string|null $dateColumn |
||
72 | * @param string|null $column |
||
73 | * |
||
74 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
75 | */ |
||
76 | 42 | public function count($unit, $model, $dateColumn = null, $column = null) |
|
80 | |||
81 | /** |
||
82 | * Return a value result showing a average aggregate over time. |
||
83 | * |
||
84 | * @param string $unit |
||
85 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
86 | * @param string $column |
||
87 | * @param string|null $dateColumn |
||
88 | * |
||
89 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
90 | */ |
||
91 | 12 | public function average(string $unit, $model, $column, $dateColumn = null) |
|
95 | |||
96 | /** |
||
97 | * Return a value result showing a sum aggregate over time. |
||
98 | * |
||
99 | * @param string $unit |
||
100 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
101 | * @param string $column |
||
102 | * @param string|null $dateColumn |
||
103 | * |
||
104 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
105 | */ |
||
106 | public function sum(string $unit, $model, $column, $dateColumn = null) |
||
110 | |||
111 | /** |
||
112 | * Return a value result showing a max aggregate over time. |
||
113 | * |
||
114 | * @param string $unit |
||
115 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
116 | * @param string $column |
||
117 | * @param string|null $dateColumn |
||
118 | * |
||
119 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
120 | */ |
||
121 | public function max(string $unit, $model, $column, $dateColumn = null) |
||
125 | |||
126 | /** |
||
127 | * Return a value result showing a min aggregate over time. |
||
128 | * |
||
129 | * @param string $unit |
||
130 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
131 | * @param string $column |
||
132 | * @param string|null $dateColumn |
||
133 | * |
||
134 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
135 | */ |
||
136 | public function min(string $unit, $model, $column, $dateColumn = null) |
||
140 | |||
141 | /** |
||
142 | * Make a new result instance. |
||
143 | * |
||
144 | * @param mixed|null $value |
||
145 | * |
||
146 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
147 | */ |
||
148 | 54 | protected function result($value = null) |
|
152 | |||
153 | /* ----------------------------------------------------------------- |
||
154 | | Other Methods |
||
155 | | ----------------------------------------------------------------- |
||
156 | */ |
||
157 | |||
158 | /** |
||
159 | * Handle the aggregate calculation of the metric. |
||
160 | * |
||
161 | * @param string $method |
||
162 | * @param string $unit |
||
163 | * @param \Illuminate\Database\Eloquent\Builder|string $model |
||
164 | * @param string|null $column |
||
165 | * @param string|null $dateColumn |
||
166 | * |
||
167 | * @return \Arcanedev\LaravelMetrics\Results\TrendResult|mixed |
||
168 | */ |
||
169 | 54 | protected function aggregate(string $method, string $unit, $model, ?string $column = null, ?string $dateColumn = null) |
|
223 | |||
224 | /** |
||
225 | * Parse the date result. |
||
226 | * |
||
227 | * @param string $date |
||
228 | * @param string $unit |
||
229 | * |
||
230 | * @return \Cake\Chronos\Chronos |
||
231 | */ |
||
232 | 54 | protected function parseDateResult(string $date, string $unit): Chronos |
|
256 | |||
257 | /** |
||
258 | * Get the instance as an array. |
||
259 | * |
||
260 | * @return array |
||
261 | */ |
||
262 | 6 | public function toArray(): array |
|
269 | } |
||
270 |
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: