Skip to content

feat: update PHPStan lvl to 5 #91

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

Open
wants to merge 5 commits into
base: develop
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
2 changes: 1 addition & 1 deletion .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

10 changes: 5 additions & 5 deletions lib/FailureHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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()
{
Expand Down
7 changes: 4 additions & 3 deletions lib/Job/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/Job/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
34 changes: 18 additions & 16 deletions lib/JobHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +26,7 @@
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;

Expand All @@ -52,7 +53,7 @@
/**
* @var Job Instance of the class performing work for this job.
*/
private $instance;

Check failure on line 56 in lib/JobHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan

Property Resque\JobHandler::$instance is never written, only read.

/**
* @var \Resque\Job\FactoryInterface
Expand All @@ -79,12 +80,12 @@
/**
* 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<Job> $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
*/
Expand Down Expand Up @@ -192,16 +193,17 @@

/**
* 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)) {

Check failure on line 201 in lib/JobHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan

Property Resque\JobHandler::$instance (Resque\Job\Job) in isset() is not nullable.
return $this->instance;
}

$this->instance = $this->getJobFactory()->create($this->payload['class'], $this->getArguments(), $this->queue);
$this->instance = $this->getJobFactory()

Check failure on line 205 in lib/JobHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan

Unreachable statement - code above always terminates.
->create($this->payload['class'], $this->getArguments(), $this->queue);
$this->instance->job = $this;
$this->instance->jobID = $this->payload['id'];
return $this->instance;
Expand All @@ -211,8 +213,8 @@
* 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()
{
Expand Down Expand Up @@ -325,8 +327,8 @@
}

/**
* @param Resque\Job\FactoryInterface $jobFactory
* @return Resque\JobHandler
* @param \Resque\Job\FactoryInterface $jobFactory
* @return \Resque\JobHandler
*/
public function setJobFactory(FactoryInterface $jobFactory)
{
Expand All @@ -336,7 +338,7 @@
}

/**
* @return Resque\Job\FactoryInterface
* @return \Resque\Job\FactoryInterface
*/
public function getJobFactory(): FactoryInterface
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Chris Boulton <[email protected]>
* @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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/Resque.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -195,7 +195,7 @@ public static function blpop(array $queues, $timeout)
$item = self::redis()->blpop($list, (int)$timeout);

if (!$item) {
return;
return null;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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)
{
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions lib/Worker/ResqueWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -349,7 +349,7 @@ public function reserve($blocking = false, $timeout = null)

$queues = $this->queues();
if (!is_array($queues)) {
return;
return false;
}

if ($blocking === true) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<string, mixed> Object with details of current job.
*/
public function job()
{
Expand Down
Loading