Skip to content

Commit

Permalink
Add var type hints to help phpstran
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jan 24, 2024
1 parent 99f260d commit 9fbba89
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ public function isDue(DateTimeInterface $dateTime): bool
public function getNextDue(DateTimeInterface $dateTime): DateTimeInterface
{
if ($this->isExpired($dateTime)) {
return $this->end;
/** @var DateTimeInterface $end */
$end = $this->end;

return $end;
}

if ($dateTime < $this->start) {
return $this->start;
/** @var DateTimeInterface $start */
$start = $this->start;

return $start;
}

return $this->cron->getNextRunDate($dateTime);
Expand Down Expand Up @@ -187,6 +193,9 @@ public static function fromJson(string $json): Frequency
return $self;
}

/**
* @return array<string, string>
*/
public function jsonSerialize(): array
{
$data = ['expression' => $this->getExpression()];
Expand Down
21 changes: 17 additions & 4 deletions src/RRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ public function isDue(DateTimeInterface $dateTime): bool
public function getNextDue(DateTimeInterface $dateTime): DateTimeInterface
{
if ($this->isExpired($dateTime)) {
return $this->getEnd();
/** @var DateTimeInterface $end */
$end = $this->getEnd();

return $end;
}

$nextDue = $this->getNextRecurrences($dateTime, 1, false);
Expand Down Expand Up @@ -194,7 +197,9 @@ public function startAt(DateTimeInterface $start): self
// the transformer operates only up to seconds level. See also the upstream issue #155
$startDate->setTime($start->format('H'), $start->format('i'), $start->format('s'));
// In case start time uses a different tz than what the rrule internally does, we force it to use the same
$startDate->setTimezone(new DateTimeZone($this->rrule->getTimezone()));
/** @var string $timeZone */
$timeZone = $this->rrule->getTimezone();
$startDate->setTimezone(new DateTimeZone($timeZone));

$this->rrule->setStartDate($startDate);

Expand Down Expand Up @@ -267,7 +272,9 @@ public function getNextRecurrences(
if (! $this->rrule->repeatsIndefinitely()) {
// When accessing this method externally (not by using `getNextDue()`), the transformer may
// generate recurrences beyond the configured end time.
$constraint = new BetweenConstraint($dateTime, $this->getEnd(), $include);
/** @var DateTimeInterface $end */
$end = $this->getEnd();
$constraint = new BetweenConstraint($dateTime, $end, $include);
}

// Setting the start date to a date time smaller than now causes the underlying library
Expand All @@ -284,6 +291,9 @@ public function getNextRecurrences(
}
}

/**
* @return array<string, string>
*/
public function jsonSerialize(): array
{
$data = [
Expand Down Expand Up @@ -323,6 +333,9 @@ public function __call(string $methodName, array $args)
);
}

return call_user_func_array([$this->rrule, $methodName], $args);
/** @var callable $callBack */
$callBack = [$this->rrule, $methodName];

return call_user_func_array($callBack, $args);
}
}
5 changes: 4 additions & 1 deletion src/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use ipl\Scheduler\Contract\Task;
use ipl\Stdlib\Events;
use React\EventLoop\Loop;
use React\EventLoop\TimerInterface;
use React\Promise;
use React\Promise\ExtendedPromiseInterface;
use SplObjectStorage;
Expand Down Expand Up @@ -283,7 +284,9 @@ public function isValidEvent(string $event): bool
*/
protected function cancelTask(Task $task): void
{
Loop::cancelTimer($this->detachTimer($task->getUuid()));
/** @var TimerInterface $timer */
$timer = $this->detachTimer($task->getUuid());
Loop::cancelTimer($timer);

/** @var ExtendedPromiseInterface[] $promises */
$promises = $this->detachPromises($task->getUuid());
Expand Down

0 comments on commit 9fbba89

Please sign in to comment.