diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml index d2c1bd6..0d2eeae 100644 --- a/.github/workflows/php-test.yml +++ b/.github/workflows/php-test.yml @@ -89,5 +89,5 @@ jobs: run: composer install - name: Run PHPStan - run: ./vendor/bin/phpstan analyse lib -l1 + run: ./vendor/bin/phpstan analyse lib -l5 diff --git a/lib/FailureHandler.php b/lib/FailureHandler.php index c2c2038..8c7c78c 100644 --- a/lib/FailureHandler.php +++ b/lib/FailureHandler.php @@ -23,8 +23,8 @@ class FailureHandler /** * Create a new failed job on the backend. * - * @param object $payload The contents of the job that has just failed. - * @param \Exception $exception The exception generated when the job failed to run. + * @param object|array $payload The contents of the job that has just failed. + * @param \Exception $exception The exception generated when the job failed to run. * @param \Resque\Worker\ResqueWorker $worker Instance of Resque\Worker\ResqueWorker * that was running this job when it failed. * @param string $queue The name of the queue that this job was fetched from. @@ -38,8 +38,8 @@ public static function create($payload, Exception $exception, ResqueWorker $work /** * Create a new failed job on the backend from PHP 7 errors. * - * @param object $payload The contents of the job that has just failed. - * @param \Error $exception The PHP 7 error generated when the job failed to run. + * @param object|array $payload The contents of the job that has just failed. + * @param \Error $exception The PHP 7 error generated when the job failed to run. * @param \Resque\Worker\ResqueWorker $worker Instance of Resque\Worker\ResqueWorker * that was running this job when it failed. * @param string $queue The name of the queue that this job was fetched from. @@ -53,7 +53,7 @@ public static function createFromError($payload, Error $exception, ResqueWorker /** * Return an instance of the backend for saving job failures. * - * @return object Instance of backend object. + * @return object|string Instance of backend object. */ public static function getBackend() { diff --git a/lib/Job/Factory.php b/lib/Job/Factory.php index 05b0bf6..10228da 100644 --- a/lib/Job/Factory.php +++ b/lib/Job/Factory.php @@ -7,9 +7,10 @@ class Factory implements FactoryInterface { /** - * @param $className - * @param array $args - * @param $queue + * @param class-string<\Resque\Job\Job> $className + * @param array $args + * @param string $queue + * * @return \Resque\Job\Job * @throws \Resque\Exceptions\ResqueException */ diff --git a/lib/Job/Status.php b/lib/Job/Status.php index acfdf52..2348bfd 100644 --- a/lib/Job/Status.php +++ b/lib/Job/Status.php @@ -97,7 +97,8 @@ public function isTracking() /** * Update the status indicator for the current job with a new status. * - * @param int The status of the job (see constants in Resque\Job\Status) + * @param int $status The status of the job (see constants in Resque\Job\Status) + * @param mixed $result The result of the job */ public function update($status, $result = null) { diff --git a/lib/JobHandler.php b/lib/JobHandler.php index a6d2cef..a255632 100755 --- a/lib/JobHandler.php +++ b/lib/JobHandler.php @@ -5,6 +5,7 @@ use Resque\Job\PID; use Resque\Job\Status; use Resque\Exceptions\DoNotPerformException; +use Resque\Exceptions\ResqueException; use Resque\Job\FactoryInterface; use Resque\Job\Factory; use Resque\Job\Job; @@ -25,7 +26,7 @@ class JobHandler public $queue; /** - * @var \Resque\Worker\Resque Instance of the Resque worker running this job. + * @var \Resque\Worker\ResqueWorker Instance of the Resque worker running this job. */ public $worker; @@ -79,12 +80,12 @@ public function __construct($queue, $payload) /** * Create a new job and save it to the specified queue. * - * @param string $queue The name of the queue to place the job in. - * @param string $class The name of the class that contains the code to execute the job. - * @param array $args Any optional arguments that should be passed when the job is executed. - * @param boolean $monitor Set to true to be able to monitor the status of a job. - * @param string $id Unique identifier for tracking the job. Generated if not supplied. - * @param string $prefix The prefix needs to be set for the status key + * @param string $queue The name of the queue to place the job in. + * @param class-string $class The name of the class that contains the code to execute the job. + * @param array $args Any optional arguments that should be passed when the job is executed. + * @param boolean $monitor Set to true to be able to monitor the status of a job. + * @param string $id Unique identifier for tracking the job. Generated if not supplied. + * @param string $prefix The prefix needs to be set for the status key * * @return string */ @@ -192,16 +193,17 @@ public function getArguments(): array /** * Get the instantiated object for this job that will be performing work. - * @return \Resque\Job\Job Instance of the object that this job belongs to. - * @throws \Resque\Exceptions\ResqueException + * @return Job Instance of the object that this job belongs to. + * @throws ResqueException */ public function getInstance(): Job { - if (!is_null($this->instance)) { + if (isset($this->instance)) { return $this->instance; } - $this->instance = $this->getJobFactory()->create($this->payload['class'], $this->getArguments(), $this->queue); + $this->instance = $this->getJobFactory() + ->create($this->payload['class'], $this->getArguments(), $this->queue); $this->instance->job = $this; $this->instance->jobID = $this->payload['id']; return $this->instance; @@ -211,8 +213,8 @@ public function getInstance(): Job * Actually execute a job by calling the perform method on the class * associated with the job with the supplied arguments. * - * @return mixed - * @throws Resque\Exceptions\ResqueException When the job's class could not be found. + * @return mixed Return of perform, or false if DoNotPerformException was thrown + * @throws ResqueException When the job's class could not be found. */ public function perform() { @@ -325,8 +327,8 @@ public function __toString() } /** - * @param Resque\Job\FactoryInterface $jobFactory - * @return Resque\JobHandler + * @param \Resque\Job\FactoryInterface $jobFactory + * @return \Resque\JobHandler */ public function setJobFactory(FactoryInterface $jobFactory) { @@ -336,7 +338,7 @@ public function setJobFactory(FactoryInterface $jobFactory) } /** - * @return Resque\Job\FactoryInterface + * @return \Resque\Job\FactoryInterface */ public function getJobFactory(): FactoryInterface { diff --git a/lib/Redis.php b/lib/Redis.php index 8378e2b..35c1288 100644 --- a/lib/Redis.php +++ b/lib/Redis.php @@ -15,7 +15,7 @@ * @author Chris Boulton * @license http://www.opensource.org/licenses/mit-license.php * - * @method array|null blpop(string $keyN, int $timeout) + * @method array|null blpop(string|string[] $keyN, int $timeout) * @method int decrby(string $key, int $decrement) * @method int del(string|array ...$keys) * @method int exists(string $key) @@ -27,7 +27,7 @@ * @method string|null lpop(string $key) * @method array lrange(string $key, int $start, int $stop) * @method int lrem(string $key, int $count, mixed $value) - * @method string ping(string|null $name = null) + * @method string|bool ping(string|null $name = null) * @method string|null rpop(string $key) * @method string|null rpoplpush(string $source, string $destination) * @method int rpush(string $key, mixed $value, mixed $valueN = null) @@ -146,7 +146,7 @@ public static function prefix($namespace) } /** - * @param string|array $server A DSN or array + * @param string|array|object $server A DSN or array * @param int $database A database number to select. However, if we find a valid database number in the DSN the * DSN-supplied value will be used instead and this parameter is ignored. * @param object $client Optional Credis_Cluster or Credis_Client instance instantiated by you diff --git a/lib/Resque.php b/lib/Resque.php index 384dfec..cc18fad 100644 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -19,7 +19,7 @@ class Resque public const DEFAULT_INTERVAL = 5; /** - * @var Redis Instance of Resque\Redis that talks to redis. + * @var Redis|null Instance of Resque\Redis that talks to redis. */ public static $redis = null; @@ -89,7 +89,7 @@ public static function redis() * * Will close connection to Redis before forking. * - * @return int Return vars as per pcntl_fork(). False if pcntl_fork is unavailable + * @return int|false Return vars as per pcntl_fork(). False if pcntl_fork is unavailable */ public static function fork() { @@ -135,14 +135,14 @@ public static function push($queue, $item) * return it. * * @param string $queue The name of the queue to fetch an item from. - * @return array Decoded item from the queue. + * @return array|null Decoded item from the queue. */ public static function pop($queue) { $item = self::redis()->lpop('queue:' . $queue); if (!$item) { - return; + return null; } return json_decode($item, true); @@ -195,7 +195,7 @@ public static function blpop(array $queues, $timeout) $item = self::redis()->blpop($list, (int)$timeout); if (!$item) { - return; + return null; } /** diff --git a/lib/Scheduler.php b/lib/Scheduler.php index edc3777..2d49c6f 100644 --- a/lib/Scheduler.php +++ b/lib/Scheduler.php @@ -73,7 +73,7 @@ public static function delayedPush($timestamp, $item) $redis = Resque::redis(); $redis->rpush('delayed:' . $timestamp, json_encode($item)); - $redis->zadd('delayed_queue_schedule', $timestamp, $timestamp); + $redis->zadd('delayed_queue_schedule', $timestamp, (string) $timestamp); } /** @@ -95,7 +95,7 @@ public static function getDelayedQueueScheduleSize() public static function getDelayedTimestampSize($timestamp) { $timestamp = self::getTimestamp($timestamp); - return Resque::redis()->llen('delayed:' . $timestamp, $timestamp); + return Resque::redis()->llen('delayed:' . $timestamp); } /** @@ -184,7 +184,7 @@ private static function cleanupTimestamp($key, $timestamp) if ($redis->llen($key) == 0) { $redis->del($key); - $redis->zrem('delayed_queue_schedule', $timestamp); + $redis->zrem('delayed_queue_schedule', (string) $timestamp); } } @@ -193,7 +193,7 @@ private static function cleanupTimestamp($key, $timestamp) * * @param \DateTime|int $timestamp Instance of DateTime or UNIX timestamp. * @return int Timestamp - * @throws Scheduler_InvalidTimestampException + * @throws InvalidTimestampException */ private static function getTimestamp($timestamp) { @@ -218,8 +218,8 @@ private static function getTimestamp($timestamp) * that any jobs scheduled for the past when the worker wasn't running are * also queued up. * - * @param \DateTime|int $timestamp Instance of DateTime or UNIX timestamp. - * Defaults to now. + * @param \DateTime|int $at Instance of DateTime or UNIX timestamp. + * Defaults to now. * @return int|false UNIX timestamp, or false if nothing to run. */ public static function nextDelayedTimestamp($at = null) diff --git a/lib/Worker/ResqueWorker.php b/lib/Worker/ResqueWorker.php index d400f72..f09ce40 100644 --- a/lib/Worker/ResqueWorker.php +++ b/lib/Worker/ResqueWorker.php @@ -69,12 +69,12 @@ class ResqueWorker private $id; /** - * @var \Resque\JobHandler Current job, if any, being processed by this worker. + * @var \Resque\JobHandler|null Current job, if any, being processed by this worker. */ private $currentJob = null; /** - * @var int Process ID of child worker processes. + * @var int|null Process ID of child worker processes. */ private $child = null; @@ -145,7 +145,7 @@ public static function exists($workerId) * Given a worker ID, find it and return an instantiated worker class for it. * * @param string $workerId The ID of the worker. - * @return \Resque\Worker\ResqueWorker Instance of the worker. False if the worker does not exist. + * @return \Resque\Worker\ResqueWorker|false Instance of the worker. False if the worker does not exist. */ public static function find($workerId) { @@ -338,7 +338,7 @@ public function perform(JobHandler $job) /** * @param bool $blocking * @param int $timeout - * @return object|boolean Instance of Resque\JobHandler if a job is found, false if not. + * @return \Resque\JobHandler|boolean Instance of Resque\JobHandler if a job is found, false if not. */ public function reserve($blocking = false, $timeout = null) { @@ -349,7 +349,7 @@ public function reserve($blocking = false, $timeout = null) $queues = $this->queues(); if (!is_array($queues)) { - return; + return false; } if ($blocking === true) { @@ -423,7 +423,7 @@ private function startup() */ private function updateProcLine($status) { - $processTitle = static::$processPrefix . '-' . Resque::VERSION; + $processTitle = self::$processPrefix . '-' . Resque::VERSION; $processTitle .= ' (' . implode(',', $this->queues) . '): ' . $status; if (function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') { cli_set_process_title($processTitle); @@ -605,7 +605,7 @@ public function unregisterWorker() /** * Tell Redis which job we're currently working on. * - * @param object $job \Resque\JobHandler instance containing the job we're working on. + * @param \Resque\JobHandler $job instance containing the job we're working on. */ public function workingOn(JobHandler $job) { @@ -645,7 +645,7 @@ public function __toString() /** * Return an object describing the job this worker is currently working on. * - * @return object Object with details of current job. + * @return array Object with details of current job. */ public function job() {