Skip to content

Commit

Permalink
Define php objects on use then use protection visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
stephpy committed Dec 21, 2023
1 parent 04445a9 commit c5f2d0b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Timezones/TimezoneRangeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Spatie\IcalendarGenerator\Timezones;

use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
use Exception;

class TimezoneRangeCollection
Expand Down Expand Up @@ -96,10 +98,10 @@ private function addArray(array $entries)

private function addEntry(string $timezone, DateTimeInterface $date)
{
$date = \DateTimeImmutable::createFromFormat(
$date = DateTimeImmutable::createFromFormat(
DATE_ATOM,
$date->format(DATE_ATOM)
)->setTimezone(new \DateTimeZone('UTC'));
)->setTimezone(new DateTimeZone('UTC'));

if (!array_key_exists($timezone, $this->ranges)) {
$this->ranges[$timezone] = [
Expand All @@ -108,33 +110,33 @@ private function addEntry(string $timezone, DateTimeInterface $date)
];
}

/** @var \DateTimeInterface $minimum */
/** @var DateTimeInterface $minimum */
$minimum = $this->ranges[$timezone]['min'];

if ($date < $minimum) {
$this->ranges[$timezone]['min'] = $date;
}

/** @var \DateTimeInterface $maximum */
/** @var DateTimeInterface $maximum */
$maximum = $this->ranges[$timezone]['max'];

if ($date > $maximum) {
$this->ranges[$timezone]['max'] = $date;
}
}

private function getMinimumDateTimeImmutable(): \DateTimeImmutable
protected function getMinimumDateTimeImmutable(): DateTimeImmutable
{
return PHP_INT_SIZE === 4 ?
(new \DateTimeImmutable())->setTimestamp(~PHP_INT_MAX) :
(new \DateTimeImmutable('0001-01-01 0:0:0'));
(new DateTimeImmutable())->setTimestamp(~PHP_INT_MAX) :
(new DateTimeImmutable('0001-01-01 0:0:0'));
}

private function getMaximumDateTimeImmutable(): \DateTimeImmutable
protected function getMaximumDateTimeImmutable(): DateTimeImmutable
{
return PHP_INT_SIZE === 4 ?
(new \DateTimeImmutable())->setTimestamp(PHP_INT_MAX) :
(new \DateTimeImmutable('9999-12-31 23:59:59'));
(new DateTimeImmutable())->setTimestamp(PHP_INT_MAX) :
(new DateTimeImmutable('9999-12-31 23:59:59'));
}

}

0 comments on commit c5f2d0b

Please sign in to comment.