for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php namespace Arcanedev\LaravelMetrics\Metrics\Concerns;
/**
* Trait HasRanges
*
* @package Arcanedev\LaravelMetrics\Metrics\Concerns
* @author ARCANEDEV <[email protected]>
* @property \Illuminate\Http\Request $request
* @method array ranges()
*/
trait HasRanges
{
/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
* Convert the ranges for json serialization.
* @return array
public function rangesToArray(): array
$ranges = method_exists($this, 'ranges') ? $this->ranges() : [];
return array_map(function ($value, $label) {
return compact('value', 'label');
}, array_keys($ranges), $ranges);
}
* Calculate the current range.
* @param string|int $range
* @param \Cake\Chronos\Chronos $now
protected function currentRange($range, $now): array
return [
$now->subDays($range),
$now,
];
* Calculate the previous range.
protected function previousRange($range, $now): array
$now->subDays($range * 2),
$now->subDays($range)->subSeconds(1),