Daily.php
2 years ago
Hourly.php
2 years ago
Interval.php
2 years ago
Intervals.php
2 years ago
Monthly.php
2 years ago
Weekly.php
2 years ago
Intervals.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Statistics\Intervals; |
| 4 | |
| 5 | /** @internal */ |
| 6 | class Intervals |
| 7 | { |
| 8 | /** |
| 9 | * @return Interval[] |
| 10 | */ |
| 11 | public static function all() : array |
| 12 | { |
| 13 | return [new Hourly(), new Daily(), new Weekly(), new Monthly()]; |
| 14 | } |
| 15 | /** |
| 16 | * Find an interval by its id. Will return the default interval if provided id is invalid. |
| 17 | * |
| 18 | * @param string|null $interval_id |
| 19 | * |
| 20 | * @return Interval |
| 21 | */ |
| 22 | public static function find_by_id(?string $interval_id) : Interval |
| 23 | { |
| 24 | foreach (self::all() as $interval) { |
| 25 | if ($interval->id() === $interval_id) { |
| 26 | return $interval; |
| 27 | } |
| 28 | } |
| 29 | return new Daily(); |
| 30 | } |
| 31 | public static function default_for(int $days) : Interval |
| 32 | { |
| 33 | if ($days <= 3) { |
| 34 | return new Hourly(); |
| 35 | } elseif ($days <= 84) { |
| 36 | return new Daily(); |
| 37 | } elseif ($days <= 182) { |
| 38 | return new Weekly(); |
| 39 | } else { |
| 40 | return new Monthly(); |
| 41 | } |
| 42 | } |
| 43 | // public static function create_interval(?string $interval_id): Interval |
| 44 | // { |
| 45 | // // Switch case... |
| 46 | // } |
| 47 | } |
| 48 |