diff --git a/psalm.xml b/psalm.xml index 507ccb6..53ffdb4 100644 --- a/psalm.xml +++ b/psalm.xml @@ -2,7 +2,7 @@ diff --git a/src/Core/Dispatchers/WaitEventDispatcher.php b/src/Core/Dispatchers/WaitEventDispatcher.php index f14671b..d602167 100644 --- a/src/Core/Dispatchers/WaitEventDispatcher.php +++ b/src/Core/Dispatchers/WaitEventDispatcher.php @@ -21,10 +21,10 @@ public function dispatch(MayPromised $promised): void PromiseEvent::saveWaitEvent($promised); // Чтобы сохранить ID события в задачу-обертку - $promise_job = PromiseJob::find($promised->getBaseJobId()); - if ($promise_job !== null) { - $promise_job->initial_job = $promised; - $promise_job->save(); + $promiseJob = PromiseJob::find($promised->getBaseJobId()); + if ($promiseJob !== null) { + $promiseJob->initial_job = $promised; + $promiseJob->save(); } } } diff --git a/src/Core/GarbageCollector.php b/src/Core/GarbageCollector.php index f5310e6..4f369ab 100644 --- a/src/Core/GarbageCollector.php +++ b/src/Core/GarbageCollector.php @@ -25,7 +25,7 @@ public function __construct(int $sleepTime, int $deleteOlderThen, array $states) $this->sleepTime = $sleepTime; $this->deleteOlderThen = $deleteOlderThen; $this->states = $states; - $this->lastIteration = Carbon::parse(0); + $this->lastIteration = Carbon::minValue(); } /** diff --git a/src/Core/Support/PromiseQueueJob.php b/src/Core/Support/PromiseQueueJob.php index 52bac01..970d421 100644 --- a/src/Core/Support/PromiseQueueJob.php +++ b/src/Core/Support/PromiseQueueJob.php @@ -6,6 +6,7 @@ use Illuminate\Container\Container; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Support\Collection; use Tochka\Promises\Contracts\JobFacadeContract; use Tochka\Promises\Contracts\JobStateContract; use Tochka\Promises\Contracts\MayPromised; @@ -134,21 +135,24 @@ protected function dispatchMethodWithParams(string $method) } /** - * @return array> + * @return array, non-empty-list> */ private function getResults(): array { $results = []; - $jobs = PromiseJob::byPromise($this->getPromiseId())->orderBy('id')->get(); - /** @var PromiseJob $job */ + /** @var Collection $jobs */ + $jobs = PromiseJob::byPromise($this->getPromiseId()) + ->orderBy('id') + ->get(); + foreach ($jobs as $job) { $resultJob = $job->getBaseJob()->getResultJob(); - $results[\get_class($resultJob)][] = $resultJob; + $results[$resultJob::class][] = $resultJob; if ($resultJob instanceof WaitEvent) { $resultEvent = $resultJob->getEvent(); if ($resultEvent !== null) { - $results[\get_class($resultEvent)][] = $resultEvent; + $results[$resultEvent::class][] = $resultEvent; } } } diff --git a/src/Models/Casts/ConditionsCast.php b/src/Models/Casts/ConditionsCast.php index 6f140f1..a4dbc50 100644 --- a/src/Models/Casts/ConditionsCast.php +++ b/src/Models/Casts/ConditionsCast.php @@ -6,7 +6,7 @@ use Tochka\Promises\Core\Support\ConditionTransition; /** - * @template-implements CastsAttributes, string> + * @template-implements CastsAttributes, array> */ class ConditionsCast implements CastsAttributes { diff --git a/src/Models/PromiseJob.php b/src/Models/PromiseJob.php index 2ebea15..3e1c02d 100644 --- a/src/Models/PromiseJob.php +++ b/src/Models/PromiseJob.php @@ -1,7 +1,5 @@ nestedEvents = $nestedEvents; } diff --git a/src/Registry/PromiseEventRegistry.php b/src/Registry/PromiseEventRegistry.php index ce06c2c..c182d01 100644 --- a/src/Registry/PromiseEventRegistry.php +++ b/src/Registry/PromiseEventRegistry.php @@ -15,31 +15,26 @@ class PromiseEventRegistry /** * @param string $event_name * @param string $event_unique_id - * - * @return \Tochka\Promises\Support\WaitEvent[]|Collection + * @return Collection */ public function loadByEvent(string $event_name, string $event_unique_id): Collection { + /** @psalm-suppress InvalidTemplateParam */ return PromiseEvent::byEvent($event_name, $event_unique_id) ->get() ->map( - function (PromiseEvent $promiseEventModel) { + function (PromiseEvent $promiseEventModel): WaitEvent { return $promiseEventModel->getWaitEvent(); } ); } - /** - * @param \Tochka\Promises\Support\WaitEvent $waitEvent - */ public function save(WaitEvent $waitEvent): void { PromiseEvent::saveWaitEvent($waitEvent); } /** - * @param int $id - * * @throws \Exception */ public function delete(int $id): void diff --git a/src/Registry/PromiseJobRegistry.php b/src/Registry/PromiseJobRegistry.php index c27f3d1..075ce3f 100644 --- a/src/Registry/PromiseJobRegistry.php +++ b/src/Registry/PromiseJobRegistry.php @@ -26,14 +26,15 @@ public function load(int $id): BaseJob /** * @param int $promise_id * - * @return \Illuminate\Support\Collection|BaseJob[] + * @return Collection */ public function loadByPromiseId(int $promise_id): Collection { + /** @psalm-suppress InvalidTemplateParam */ return PromiseJob::byPromise($promise_id) ->get() ->map( - function (PromiseJob $jobModel) { + function (PromiseJob $jobModel): BaseJob { return $jobModel->getBaseJob(); } );