for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Adlogix\EventScheduler\DateRange;
use DateTimeImmutable;
use DateTimeInterface;
use InvalidArgumentException;
/**
* @author Toni Van de Voorde <[email protected]>
*/
final class DateRange
{
* @var DateTimeImmutable
protected $startDate;
protected $endDate;
* @param DateTimeInterface $startDate
* @param DateTimeInterface $endDate
public function __construct(DateTimeInterface $startDate, DateTimeInterface $endDate)
if ($startDate > $endDate) {
throw new InvalidArgumentException('The start date must be more recent that end date');
}
$this->startDate = $this->makeImmutable($startDate);
$this->endDate = $this->makeImmutable($endDate);
* @param DateTimeInterface $date
* @return DateTimeImmutable
private function makeImmutable(DateTimeInterface $date): DateTimeImmutable
return ($date instanceof DateTimeImmutable)
? $date
: DateTimeImmutable::createFromMutable($date);
public function startDate(): DateTimeImmutable
return $this->startDate;
public function endDate(): DateTimeImmutable
return $this->endDate;