Skip to content

Commit 7b9d3d7

Browse files
authored
Merge pull request #22 from programmatordev/OPA-31-change-dates-type-hint-to-datetimeinterface
Changed dates type hint to \DateTimeInterface
2 parents f2ee56d + 54eec9a commit 7b9d3d7

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

src/Endpoint/AirPollutionEndpoint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public function getForecast(float $latitude, float $longitude): AirPollutionList
8989
public function getHistory(
9090
float $latitude,
9191
float $longitude,
92-
\DateTimeImmutable $startDate,
93-
\DateTimeImmutable $endDate
92+
\DateTimeInterface $startDate,
93+
\DateTimeInterface $endDate
9494
): AirPollutionList
9595
{
9696
$this->validateCoordinate($latitude, $longitude);

src/Endpoint/OneCallEndpoint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function getWeather(float $latitude, float $longitude): OneCall
6666
* @throws UnexpectedErrorException
6767
* @throws InvalidArgumentException
6868
*/
69-
public function getHistoryMoment(float $latitude, float $longitude, \DateTimeImmutable $dateTime): HistoryMoment
69+
public function getHistoryMoment(float $latitude, float $longitude, \DateTimeInterface $dateTime): HistoryMoment
7070
{
7171
$this->validateCoordinate($latitude, $longitude);
7272
$this->validateLessThan('dateTime', $dateTime, new \DateTimeImmutable('now'));
@@ -95,7 +95,7 @@ public function getHistoryMoment(float $latitude, float $longitude, \DateTimeImm
9595
* @throws UnexpectedErrorException
9696
* @throws InvalidArgumentException
9797
*/
98-
public function getHistoryDaySummary(float $latitude, float $longitude, \DateTimeImmutable $dateTime): HistoryDaySummary
98+
public function getHistoryDaySummary(float $latitude, float $longitude, \DateTimeInterface $dateTime): HistoryDaySummary
9999
{
100100
$this->validateCoordinate($latitude, $longitude);
101101
$this->validateLessThan('dateTime', $dateTime, new \DateTimeImmutable('now'));

src/Validator/BetweenValidatorTrait.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ trait BetweenValidatorTrait
66
{
77
private function ValidateBetween(
88
string $name,
9-
\DateTimeImmutable|int|float $value,
10-
\DateTimeImmutable|int|float $startConstraint,
11-
\DateTimeImmutable|int|float $endConstraint
9+
\DateTimeInterface|int|float $value,
10+
\DateTimeInterface|int|float $startConstraint,
11+
\DateTimeInterface|int|float $endConstraint
1212
): void
1313
{
1414
if (
15-
$value instanceof \DateTimeImmutable
16-
&& (!$startConstraint instanceof \DateTimeImmutable || !$endConstraint instanceof \DateTimeImmutable)
15+
$value instanceof \DateTimeInterface
16+
&& (!$startConstraint instanceof \DateTimeInterface || !$endConstraint instanceof \DateTimeInterface)
1717
) {
18-
throw new \LogicException('Both $startConstraint and $endConstraint should be of type \DateTimeImmutable.');
18+
throw new \LogicException('Both $startConstraint and $endConstraint should be of type \DateTimeInterface.');
1919
}
2020

2121
if (
22-
!$value instanceof \DateTimeImmutable
23-
&& ($startConstraint instanceof \DateTimeImmutable || $endConstraint instanceof \DateTimeImmutable)
22+
!$value instanceof \DateTimeInterface
23+
&& ($startConstraint instanceof \DateTimeInterface || $endConstraint instanceof \DateTimeInterface)
2424
) {
2525
throw new \LogicException('Both $startConstraint and $endConstraint should be of type int|float.');
2626
}
2727

28-
if ($value instanceof \DateTimeImmutable) {
28+
if ($value instanceof \DateTimeInterface) {
2929
if ($value->getTimestamp() < $startConstraint->getTimestamp() || $value->getTimestamp() > $endConstraint->getTimestamp()) {
3030
$dateFormat = 'Y-m-d H:i:s';
3131

src/Validator/GreaterThanValidatorTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ trait GreaterThanValidatorTrait
66
{
77
private function validateGreaterThan(
88
string $name,
9-
\DateTimeImmutable|int|float $value,
10-
\DateTimeImmutable|int|float $constraint
9+
\DateTimeInterface|int|float $value,
10+
\DateTimeInterface|int|float $constraint
1111
): void
1212
{
13-
if ($value instanceof \DateTimeImmutable && !$constraint instanceof \DateTimeImmutable) {
14-
throw new \LogicException('$constraint should be of type \DateTimeImmutable.');
13+
if ($value instanceof \DateTimeInterface && !$constraint instanceof \DateTimeInterface) {
14+
throw new \LogicException('$constraint should be of type \DateTimeInterface.');
1515
}
1616

17-
if (!$value instanceof \DateTimeImmutable && $constraint instanceof \DateTimeImmutable) {
17+
if (!$value instanceof \DateTimeInterface && $constraint instanceof \DateTimeInterface) {
1818
throw new \LogicException('$constraint should be of type int|float.');
1919
}
2020

21-
if ($value instanceof \DateTimeImmutable) {
21+
if ($value instanceof \DateTimeInterface) {
2222
if ($value->getTimestamp() <= $constraint->getTimestamp()) {
2323
$dateFormat = 'Y-m-d H:i:s';
2424

src/Validator/LessThanValidatorTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ trait LessThanValidatorTrait
66
{
77
private function validateLessThan(
88
string $name,
9-
\DateTimeImmutable|int|float $value,
10-
\DateTimeImmutable|int|float $constraint
9+
\DateTimeInterface|int|float $value,
10+
\DateTimeInterface|int|float $constraint
1111
): void
1212
{
13-
if ($value instanceof \DateTimeImmutable && !$constraint instanceof \DateTimeImmutable) {
14-
throw new \LogicException('$constraint should be of type \DateTimeImmutable.');
13+
if ($value instanceof \DateTimeInterface && !$constraint instanceof \DateTimeInterface) {
14+
throw new \LogicException('$constraint should be of type \DateTimeInterface.');
1515
}
1616

17-
if (!$value instanceof \DateTimeImmutable && $constraint instanceof \DateTimeImmutable) {
17+
if (!$value instanceof \DateTimeInterface && $constraint instanceof \DateTimeInterface) {
1818
throw new \LogicException('$constraint should be of type int|float.');
1919
}
2020

21-
if ($value instanceof \DateTimeImmutable) {
21+
if ($value instanceof \DateTimeInterface) {
2222
if ($value->getTimestamp() >= $constraint->getTimestamp()) {
2323
$dateFormat = 'Y-m-d H:i:s';
2424

src/Validator/RangeValidatorTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ trait RangeValidatorTrait
99
public function validateRange(
1010
string $startName,
1111
string $endName,
12-
\DateTimeImmutable|int|float $startValue,
13-
\DateTimeImmutable|int|float $endValue
12+
\DateTimeInterface|int|float $startValue,
13+
\DateTimeInterface|int|float $endValue
1414
): void
1515
{
1616
if (
17-
($startValue instanceof \DateTimeImmutable && !$endValue instanceof \DateTimeImmutable)
18-
|| (!$startValue instanceof \DateTimeImmutable && $endValue instanceof \DateTimeImmutable)
17+
($startValue instanceof \DateTimeInterface && !$endValue instanceof \DateTimeInterface)
18+
|| (!$startValue instanceof \DateTimeInterface && $endValue instanceof \DateTimeInterface)
1919
) {
20-
throw new \LogicException('Both $startValue and $endValue should be of type \DateTimeImmutable or int|float.');
20+
throw new \LogicException('Both $startValue and $endValue should be of type \DateTimeInterface or int|float.');
2121
}
2222

2323
try {
2424
$this->validateLessThan('startValue', $startValue, $endValue);
2525
}
2626
catch (\UnexpectedValueException) {
27-
if ($startValue instanceof \DateTimeImmutable) {
27+
if ($startValue instanceof \DateTimeInterface) {
2828
$dateFormat = 'Y-m-d H:i:s';
2929

3030
throw new \UnexpectedValueException(

0 commit comments

Comments
 (0)