mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Created factory method to build VisitParams from a raw dataset
This commit is contained in:
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Model;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
|
||||
final class VisitsParams
|
||||
@@ -21,6 +22,19 @@ final class VisitsParams
|
||||
$this->itemsPerPage = $itemsPerPage;
|
||||
}
|
||||
|
||||
public static function fromRawData(array $query): self
|
||||
{
|
||||
$startDate = self::getDateQueryParam($query, 'startDate');
|
||||
$endDate = self::getDateQueryParam($query, 'endDate');
|
||||
|
||||
return new self(new DateRange($startDate, $endDate), $query['page'] ?? 1, $query['itemsPerPage'] ?? null);
|
||||
}
|
||||
|
||||
private static function getDateQueryParam(array $query, string $key): ?Chronos
|
||||
{
|
||||
return ! isset($query[$key]) || empty($query[$key]) ? null : Chronos::parse($query[$key]);
|
||||
}
|
||||
|
||||
public function getDateRange(): DateRange
|
||||
{
|
||||
return $this->dateRange;
|
||||
|
||||
Reference in New Issue
Block a user