diff --git a/src/Metric.php b/src/Metric.php index 4d6ee1f..74ab289 100644 --- a/src/Metric.php +++ b/src/Metric.php @@ -12,7 +12,7 @@ class Metric extends Model /** * The attributes that aren't mass assignable. * - * @var array + * @var array */ protected $guarded = []; @@ -37,6 +37,8 @@ protected function casts(): array /** * Create a new Eloquent query builder for the model. + * + * @return MetricBuilder */ public function newEloquentBuilder($query): MetricBuilder { diff --git a/src/MetricBuilder.php b/src/MetricBuilder.php index 2ba0956..45105ee 100644 --- a/src/MetricBuilder.php +++ b/src/MetricBuilder.php @@ -5,20 +5,29 @@ use Carbon\CarbonInterface; use Illuminate\Database\Eloquent\Builder; +/** + * @template TMetric of Metric + * + * @extends Builder + */ class MetricBuilder extends Builder { /** * Get metrics for today. + * + * @return $this */ - public function today(): self + public function today(): static { return $this->onDate(today()); } /** * Get metrics for yesterday. + * + * @return $this */ - public function yesterday(): self + public function yesterday(): static { return $this->onDate( today()->subDay() @@ -27,24 +36,30 @@ public function yesterday(): self /** * Get metrics for this hour. + * + * @return $this */ - public function thisHour(): self + public function thisHour(): static { return $this->onDateTime(now()); } /** * Get metrics for last hour. + * + * @return $this */ - public function lastHour(): self + public function lastHour(): static { return $this->onDateTime(now()->subHour()); } /** * Get metrics for this week. + * + * @return $this */ - public function thisWeek(): self + public function thisWeek(): static { return $this->betweenDates( today()->startOfWeek(), @@ -54,8 +69,10 @@ public function thisWeek(): self /** * Get metrics for last week. + * + * @return $this */ - public function lastWeek(): self + public function lastWeek(): static { return $this->betweenDates( today()->subWeek()->startOfWeek(), @@ -65,8 +82,10 @@ public function lastWeek(): self /** * Get metrics for this month. + * + * @return $this */ - public function thisMonth(): self + public function thisMonth(): static { return $this->betweenDates( today()->startOfMonth(), @@ -76,8 +95,10 @@ public function thisMonth(): self /** * Get metrics for last month. + * + * @return $this */ - public function lastMonth(): self + public function lastMonth(): static { return $this->betweenDates( today()->subMonth()->startOfMonth(), @@ -87,8 +108,10 @@ public function lastMonth(): self /** * Get metrics for last month without overflow. + * + * @return $this */ - public function lastMonthNoOverflow(): self + public function lastMonthNoOverflow(): static { return $this->betweenDates( today()->subMonthNoOverflow()->startOfMonth(), @@ -98,8 +121,10 @@ public function lastMonthNoOverflow(): self /** * Get metrics for this quarter. + * + * @return $this */ - public function thisQuarter(): self + public function thisQuarter(): static { return $this->betweenDates( today()->startOfQuarter(), @@ -109,8 +134,10 @@ public function thisQuarter(): self /** * Get metrics for last quarter. + * + * @return $this */ - public function lastQuarter(): self + public function lastQuarter(): static { return $this->betweenDates( today()->subQuarter()->startOfQuarter(), @@ -120,8 +147,10 @@ public function lastQuarter(): self /** * Get metrics for last quarter without overflow. + * + * @return $this */ - public function lastQuarterNoOverflow(): self + public function lastQuarterNoOverflow(): static { return $this->betweenDates( today()->subQuarterNoOverflow()->startOfQuarter(), @@ -131,8 +160,10 @@ public function lastQuarterNoOverflow(): self /** * Get metrics for this year. + * + * @return $this */ - public function thisYear(): self + public function thisYear(): static { return $this->betweenDates( today()->startOfYear(), @@ -142,8 +173,10 @@ public function thisYear(): self /** * Get metrics for last year. + * + * @return $this */ - public function lastYear(): self + public function lastYear(): static { return $this->betweenDates( today()->subYear()->startOfYear(), @@ -153,8 +186,10 @@ public function lastYear(): self /** * Get metrics for last year without overflow. + * + * @return $this */ - public function lastYearNoOverflow(): self + public function lastYearNoOverflow(): static { return $this->betweenDates( today()->subYearNoOverflow()->startOfYear(), @@ -164,8 +199,10 @@ public function lastYearNoOverflow(): self /** * Get metrics between two dates. + * + * @return $this */ - public function betweenDates(CarbonInterface $start, CarbonInterface $end): self + public function betweenDates(CarbonInterface $start, CarbonInterface $end): static { return $this->whereRaw( '(year, month, day) >= (?, ?, ?) AND (year, month, day) <= (?, ?, ?)', @@ -178,8 +215,10 @@ public function betweenDates(CarbonInterface $start, CarbonInterface $end): self /** * Get metrics between two datetimes (including hours). + * + * @return $this */ - public function betweenDateTimes(CarbonInterface $start, CarbonInterface $end): self + public function betweenDateTimes(CarbonInterface $start, CarbonInterface $end): static { return $this->whereRaw( '(year, month, day, hour) >= (?, ?, ?, ?) AND (year, month, day, hour) <= (?, ?, ?, ?)', @@ -192,8 +231,10 @@ public function betweenDateTimes(CarbonInterface $start, CarbonInterface $end): /** * Get metrics on a specific date. + * + * @return $this */ - public function onDate(CarbonInterface $date): self + public function onDate(CarbonInterface $date): static { return $this->where(function (Builder $query) use ($date) { $query @@ -205,8 +246,10 @@ public function onDate(CarbonInterface $date): self /** * Get metrics on a specific date and hour. + * + * @return $this */ - public function onDateTime(CarbonInterface $hour): self + public function onDateTime(CarbonInterface $hour): static { return $this->onDate($hour)->where('hour', $hour->hour); } diff --git a/src/MetricFactory.php b/src/MetricFactory.php index 48613d2..8be041b 100644 --- a/src/MetricFactory.php +++ b/src/MetricFactory.php @@ -4,6 +4,9 @@ use Illuminate\Database\Eloquent\Factories\Factory; +/** + * @extends Factory + */ class MetricFactory extends Factory { /**