Skip to content

Commit 546e5a0

Browse files
committed
feat: update PHPStan lvl to 4
feat: PHPStan l5
1 parent 7a9a8d6 commit 546e5a0

File tree

9 files changed

+50
-45
lines changed

9 files changed

+50
-45
lines changed

.github/workflows/php-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ jobs:
8989
run: composer install
9090

9191
- name: Run PHPStan
92-
run: ./vendor/bin/phpstan analyse lib -l1
92+
run: ./vendor/bin/phpstan analyse lib -l5
9393

lib/FailureHandler.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class FailureHandler
2323
/**
2424
* Create a new failed job on the backend.
2525
*
26-
* @param object $payload The contents of the job that has just failed.
27-
* @param \Exception $exception The exception generated when the job failed to run.
26+
* @param object|array $payload The contents of the job that has just failed.
27+
* @param \Exception $exception The exception generated when the job failed to run.
2828
* @param \Resque\Worker\ResqueWorker $worker Instance of Resque\Worker\ResqueWorker
2929
* that was running this job when it failed.
3030
* @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
3838
/**
3939
* Create a new failed job on the backend from PHP 7 errors.
4040
*
41-
* @param object $payload The contents of the job that has just failed.
42-
* @param \Error $exception The PHP 7 error generated when the job failed to run.
41+
* @param object|array $payload The contents of the job that has just failed.
42+
* @param \Error $exception The PHP 7 error generated when the job failed to run.
4343
* @param \Resque\Worker\ResqueWorker $worker Instance of Resque\Worker\ResqueWorker
4444
* that was running this job when it failed.
4545
* @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
5353
/**
5454
* Return an instance of the backend for saving job failures.
5555
*
56-
* @return object Instance of backend object.
56+
* @return object|string Instance of backend object.
5757
*/
5858
public static function getBackend()
5959
{

lib/Job/Factory.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
class Factory implements FactoryInterface
88
{
99
/**
10-
* @param $className
11-
* @param array $args
12-
* @param $queue
10+
* @param class-string<\Resque\Job\Job> $className
11+
* @param array $args
12+
* @param string $queue
13+
*
1314
* @return \Resque\Job\Job
1415
* @throws \Resque\Exceptions\ResqueException
1516
*/

lib/Job/Status.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public function isTracking()
9797
/**
9898
* Update the status indicator for the current job with a new status.
9999
*
100-
* @param int The status of the job (see constants in Resque\Job\Status)
100+
* @param int $status The status of the job (see constants in Resque\Job\Status)
101+
* @param int|null $result The result of the job
101102
*/
102103
public function update($status, $result = null)
103104
{

lib/JobHandler.php

+17-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Resque\Job\PID;
66
use Resque\Job\Status;
77
use Resque\Exceptions\DoNotPerformException;
8+
use Resque\Exceptions\ResqueException;
89
use Resque\Job\FactoryInterface;
910
use Resque\Job\Factory;
1011
use Resque\Job\Job;
@@ -25,7 +26,7 @@ class JobHandler
2526
public $queue;
2627

2728
/**
28-
* @var \Resque\Worker\Resque Instance of the Resque worker running this job.
29+
* @var \Resque\Worker\ResqueWorker Instance of the Resque worker running this job.
2930
*/
3031
public $worker;
3132

@@ -50,7 +51,7 @@ class JobHandler
5051
public $endTime;
5152

5253
/**
53-
* @var Job Instance of the class performing work for this job.
54+
* @var Job|null Instance of the class performing work for this job.
5455
*/
5556
private $instance;
5657

@@ -67,6 +68,7 @@ class JobHandler
6768
*/
6869
public function __construct($queue, $payload)
6970
{
71+
$this->instance = null;
7072
$this->queue = $queue;
7173
$this->payload = $payload;
7274
$this->popTime = microtime(true);
@@ -79,12 +81,12 @@ public function __construct($queue, $payload)
7981
/**
8082
* Create a new job and save it to the specified queue.
8183
*
82-
* @param string $queue The name of the queue to place the job in.
83-
* @param string $class The name of the class that contains the code to execute the job.
84-
* @param array $args Any optional arguments that should be passed when the job is executed.
85-
* @param boolean $monitor Set to true to be able to monitor the status of a job.
86-
* @param string $id Unique identifier for tracking the job. Generated if not supplied.
87-
* @param string $prefix The prefix needs to be set for the status key
84+
* @param string $queue The name of the queue to place the job in.
85+
* @param class-string $class The name of the class that contains the code to execute the job.
86+
* @param array $args Any optional arguments that should be passed when the job is executed.
87+
* @param boolean $monitor Set to true to be able to monitor the status of a job.
88+
* @param string $id Unique identifier for tracking the job. Generated if not supplied.
89+
* @param string $prefix The prefix needs to be set for the status key
8890
*
8991
* @return string
9092
*/
@@ -201,7 +203,8 @@ public function getInstance(): Job
201203
return $this->instance;
202204
}
203205

204-
$this->instance = $this->getJobFactory()->create($this->payload['class'], $this->getArguments(), $this->queue);
206+
$this->instance = $this->getJobFactory()
207+
->create($this->payload['class'], $this->getArguments(), $this->queue);
205208
$this->instance->job = $this;
206209
$this->instance->jobID = $this->payload['id'];
207210
return $this->instance;
@@ -211,8 +214,8 @@ public function getInstance(): Job
211214
* Actually execute a job by calling the perform method on the class
212215
* associated with the job with the supplied arguments.
213216
*
214-
* @return mixed
215-
* @throws Resque\Exceptions\ResqueException When the job's class could not be found.
217+
* @return bool
218+
* @throws ResqueException When the job's class could not be found.
216219
*/
217220
public function perform()
218221
{
@@ -325,8 +328,8 @@ public function __toString()
325328
}
326329

327330
/**
328-
* @param Resque\Job\FactoryInterface $jobFactory
329-
* @return Resque\JobHandler
331+
* @param \Resque\Job\FactoryInterface $jobFactory
332+
* @return \Resque\JobHandler
330333
*/
331334
public function setJobFactory(FactoryInterface $jobFactory)
332335
{
@@ -336,7 +339,7 @@ public function setJobFactory(FactoryInterface $jobFactory)
336339
}
337340

338341
/**
339-
* @return Resque\Job\FactoryInterface
342+
* @return \Resque\Job\FactoryInterface
340343
*/
341344
public function getJobFactory(): FactoryInterface
342345
{

lib/Redis.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* @method string|null lpop(string $key)
2828
* @method array lrange(string $key, int $start, int $stop)
2929
* @method int lrem(string $key, int $count, mixed $value)
30-
* @method string ping(string|null $name = null)
30+
* @method string|bool ping(string|null $name = null)
3131
* @method string|null rpop(string $key)
3232
* @method string|null rpoplpush(string $source, string $destination)
3333
* @method int rpush(string $key, mixed $value, mixed $valueN = null)
@@ -146,7 +146,7 @@ public static function prefix($namespace)
146146
}
147147

148148
/**
149-
* @param string|array $server A DSN or array
149+
* @param string|array|object $server A DSN or array
150150
* @param int $database A database number to select. However, if we find a valid database number in the DSN the
151151
* DSN-supplied value will be used instead and this parameter is ignored.
152152
* @param object $client Optional Credis_Cluster or Credis_Client instance instantiated by you

lib/Resque.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Resque
1919
public const DEFAULT_INTERVAL = 5;
2020

2121
/**
22-
* @var Redis Instance of Resque\Redis that talks to redis.
22+
* @var Redis|null Instance of Resque\Redis that talks to redis.
2323
*/
2424
public static $redis = null;
2525

@@ -89,7 +89,7 @@ public static function redis()
8989
*
9090
* Will close connection to Redis before forking.
9191
*
92-
* @return int Return vars as per pcntl_fork(). False if pcntl_fork is unavailable
92+
* @return int|false Return vars as per pcntl_fork(). False if pcntl_fork is unavailable
9393
*/
9494
public static function fork()
9595
{
@@ -135,14 +135,14 @@ public static function push($queue, $item)
135135
* return it.
136136
*
137137
* @param string $queue The name of the queue to fetch an item from.
138-
* @return array Decoded item from the queue.
138+
* @return array|null Decoded item from the queue.
139139
*/
140140
public static function pop($queue)
141141
{
142142
$item = self::redis()->lpop('queue:' . $queue);
143143

144144
if (!$item) {
145-
return;
145+
return null;
146146
}
147147

148148
return json_decode($item, true);
@@ -195,7 +195,7 @@ public static function blpop(array $queues, $timeout)
195195
$item = self::redis()->blpop($list, (int)$timeout);
196196

197197
if (!$item) {
198-
return;
198+
return null;
199199
}
200200

201201
/**

lib/Scheduler.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function delayedPush($timestamp, $item)
7373
$redis = Resque::redis();
7474
$redis->rpush('delayed:' . $timestamp, json_encode($item));
7575

76-
$redis->zadd('delayed_queue_schedule', $timestamp, $timestamp);
76+
$redis->zadd('delayed_queue_schedule', $timestamp, (string) $timestamp);
7777
}
7878

7979
/**
@@ -95,7 +95,7 @@ public static function getDelayedQueueScheduleSize()
9595
public static function getDelayedTimestampSize($timestamp)
9696
{
9797
$timestamp = self::getTimestamp($timestamp);
98-
return Resque::redis()->llen('delayed:' . $timestamp, $timestamp);
98+
return Resque::redis()->llen('delayed:' . $timestamp);
9999
}
100100

101101
/**
@@ -184,7 +184,7 @@ private static function cleanupTimestamp($key, $timestamp)
184184

185185
if ($redis->llen($key) == 0) {
186186
$redis->del($key);
187-
$redis->zrem('delayed_queue_schedule', $timestamp);
187+
$redis->zrem('delayed_queue_schedule', (string) $timestamp);
188188
}
189189
}
190190

@@ -193,7 +193,7 @@ private static function cleanupTimestamp($key, $timestamp)
193193
*
194194
* @param \DateTime|int $timestamp Instance of DateTime or UNIX timestamp.
195195
* @return int Timestamp
196-
* @throws Scheduler_InvalidTimestampException
196+
* @throws InvalidTimestampException
197197
*/
198198
private static function getTimestamp($timestamp)
199199
{
@@ -218,8 +218,8 @@ private static function getTimestamp($timestamp)
218218
* that any jobs scheduled for the past when the worker wasn't running are
219219
* also queued up.
220220
*
221-
* @param \DateTime|int $timestamp Instance of DateTime or UNIX timestamp.
222-
* Defaults to now.
221+
* @param \DateTime|int $at Instance of DateTime or UNIX timestamp.
222+
* Defaults to now.
223223
* @return int|false UNIX timestamp, or false if nothing to run.
224224
*/
225225
public static function nextDelayedTimestamp($at = null)

lib/Worker/ResqueWorker.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ class ResqueWorker
6969
private $id;
7070

7171
/**
72-
* @var \Resque\JobHandler Current job, if any, being processed by this worker.
72+
* @var \Resque\JobHandler|null Current job, if any, being processed by this worker.
7373
*/
7474
private $currentJob = null;
7575

7676
/**
77-
* @var int Process ID of child worker processes.
77+
* @var int|null Process ID of child worker processes.
7878
*/
7979
private $child = null;
8080

@@ -145,7 +145,7 @@ public static function exists($workerId)
145145
* Given a worker ID, find it and return an instantiated worker class for it.
146146
*
147147
* @param string $workerId The ID of the worker.
148-
* @return \Resque\Worker\ResqueWorker Instance of the worker. False if the worker does not exist.
148+
* @return \Resque\Worker\ResqueWorker|false Instance of the worker. False if the worker does not exist.
149149
*/
150150
public static function find($workerId)
151151
{
@@ -338,7 +338,7 @@ public function perform(JobHandler $job)
338338
/**
339339
* @param bool $blocking
340340
* @param int $timeout
341-
* @return object|boolean Instance of Resque\JobHandler if a job is found, false if not.
341+
* @return \Resque\JobHandler|boolean Instance of Resque\JobHandler if a job is found, false if not.
342342
*/
343343
public function reserve($blocking = false, $timeout = null)
344344
{
@@ -349,7 +349,7 @@ public function reserve($blocking = false, $timeout = null)
349349

350350
$queues = $this->queues();
351351
if (!is_array($queues)) {
352-
return;
352+
return false;
353353
}
354354

355355
if ($blocking === true) {
@@ -423,7 +423,7 @@ private function startup()
423423
*/
424424
private function updateProcLine($status)
425425
{
426-
$processTitle = static::$processPrefix . '-' . Resque::VERSION;
426+
$processTitle = self::$processPrefix . '-' . Resque::VERSION;
427427
$processTitle .= ' (' . implode(',', $this->queues) . '): ' . $status;
428428
if (function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') {
429429
cli_set_process_title($processTitle);
@@ -605,7 +605,7 @@ public function unregisterWorker()
605605
/**
606606
* Tell Redis which job we're currently working on.
607607
*
608-
* @param object $job \Resque\JobHandler instance containing the job we're working on.
608+
* @param \Resque\JobHandler $job instance containing the job we're working on.
609609
*/
610610
public function workingOn(JobHandler $job)
611611
{
@@ -645,7 +645,7 @@ public function __toString()
645645
/**
646646
* Return an object describing the job this worker is currently working on.
647647
*
648-
* @return object Object with details of current job.
648+
* @return array<string, mixed> Object with details of current job.
649649
*/
650650
public function job()
651651
{

0 commit comments

Comments
 (0)