Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpstan: Update baseline and add var type hints #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Method ipl\\\\Scheduler\\\\Cron\\:\\:getNextDue\\(\\) should return DateTimeInterface but returns DateTimeInterface\\|null\\.$#"
count: 2
path: src/Cron.php

-
message: "#^Method ipl\\\\Scheduler\\\\Cron\\:\\:jsonSerialize\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Cron.php

-
message: "#^Method ipl\\\\Scheduler\\\\RRule\\:\\:getNextDue\\(\\) should return DateTimeInterface but returns DateTimeInterface\\|null\\.$#"
count: 1
path: src/RRule.php

-
message: "#^Method ipl\\\\Scheduler\\\\RRule\\:\\:jsonSerialize\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/RRule.php

-
message: "#^Parameter \\#1 \\$timezone of class DateTimeZone constructor expects string, string\\|null given\\.$#"
message: "#^Parameter \\#1 \\$rrule of class Recurr\\\\Rule constructor expects string\\|null, array\\<string, mixed\\>\\|string given\\.$#"
count: 1
path: src/RRule.php

-
message: "#^Parameter \\#2 \\$before of class Recurr\\\\Transformer\\\\Constraint\\\\BetweenConstraint constructor expects DateTimeInterface, DateTimeInterface\\|null given\\.$#"
count: 1
path: src/RRule.php

-
message: "#^Parameter \\#1 \\$timer of static method React\\\\EventLoop\\\\Loop\\:\\:cancelTimer\\(\\) expects React\\\\EventLoop\\\\TimerInterface, React\\\\EventLoop\\\\TimerInterface\\|null given\\.$#"
count: 1
path: src/Scheduler.php
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@ parameters:
- '#Call to an undefined method React\\Promise\\PromiseInterface::#'

- '#Method ipl\\Scheduler\\.* should return \$this.* but returns static#'

- '#Parameter \#1 \$rrule of class Recurr\\Rule constructor expects string\|null, array.*\|string given#'

- '#Parameter \#1 \$callback of function call_user_func_array expects callable\(\): mixed, array{Recurr\\Rule, string} given#'
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
Loading