Skip to content

Commit 9ce7944

Browse files
committed
feat: update PHPStan lvl to 4
1 parent 5b0e4b2 commit 9ce7944

File tree

10 files changed

+71
-36
lines changed

10 files changed

+71
-36
lines changed

.github/workflows/php-test.yml

Lines changed: 1 addition & 1 deletion
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 -l4
9393

lib/FailureHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
class Factory implements FactoryInterface
88
{
99
/**
10-
* @param $className
11-
* @param array $args
12-
* @param $queue
10+
* @param class-string<\Resque\Job\JobInterface> $className
11+
* @param array $args
12+
* @param string $queue
1313
* @return \Resque\Job\JobInterface
1414
* @throws \Resque\Exceptions\ResqueException
1515
*/

lib/Job/JobInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace Resque\Job;
44

5+
/**
6+
* @property array $args
7+
* @property string $queue
8+
*/
59
interface JobInterface
610
{
711
/**

lib/Job/Status.php

Lines changed: 2 additions & 1 deletion
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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class JobHandler
2525
public $queue;
2626

2727
/**
28-
* @var \Resque\Worker\Resque Instance of the Resque worker running this job.
28+
* @var \Resque\Worker\ResqueWorker Instance of the Resque worker running this job.
2929
*/
3030
public $worker;
3131

@@ -35,7 +35,7 @@ class JobHandler
3535
public $payload;
3636

3737
/**
38-
* @var object|\Resque\Job\JobInterface Instance of the class performing work for this job.
38+
* @var object|\Resque\Job\JobInterface|null Instance of the class performing work for this job.
3939
*/
4040
private $instance;
4141

@@ -59,12 +59,12 @@ public function __construct($queue, $payload)
5959
/**
6060
* Create a new job and save it to the specified queue.
6161
*
62-
* @param string $queue The name of the queue to place the job in.
63-
* @param string $class The name of the class that contains the code to execute the job.
64-
* @param array $args Any optional arguments that should be passed when the job is executed.
65-
* @param boolean $monitor Set to true to be able to monitor the status of a job.
66-
* @param string $id Unique identifier for tracking the job. Generated if not supplied.
67-
* @param string $prefix The prefix needs to be set for the status key
62+
* @param string $queue The name of the queue to place the job in.
63+
* @param class-string $class The name of the class that contains the code to execute the job.
64+
* @param array|null $args Any optional arguments that should be passed when the job is executed.
65+
* @param boolean $monitor Set to true to be able to monitor the status of a job.
66+
* @param string $id Unique identifier for tracking the job. Generated if not supplied.
67+
* @param string $prefix The prefix needs to be set for the status key
6868
*
6969
* @return string
7070
* @throws \InvalidArgumentException
@@ -187,8 +187,10 @@ public function getInstance()
187187
return $this->instance;
188188
}
189189

190-
$this->instance = $this->getJobFactory()->create($this->payload['class'], $this->getArguments(), $this->queue);
190+
$this->instance = $this->getJobFactory()
191+
->create($this->payload['class'], $this->getArguments(), $this->queue);
191192
$this->instance->job = $this;
193+
192194
return $this->instance;
193195
}
194196

@@ -197,7 +199,7 @@ public function getInstance()
197199
* associated with the job with the supplied arguments.
198200
*
199201
* @return bool
200-
* @throws Resque\Exceptions\ResqueException When the job's class could not be found
202+
* @throws \Resque\Exceptions\ResqueException When the job's class could not be found
201203
* or it does not contain a perform method.
202204
*/
203205
public function perform()
@@ -308,8 +310,8 @@ public function __toString()
308310
}
309311

310312
/**
311-
* @param Resque\Job\FactoryInterface $jobFactory
312-
* @return Resque\JobHandler
313+
* @param \Resque\Job\FactoryInterface $jobFactory
314+
* @return \Resque\JobHandler
313315
*/
314316
public function setJobFactory(FactoryInterface $jobFactory)
315317
{
@@ -319,7 +321,7 @@ public function setJobFactory(FactoryInterface $jobFactory)
319321
}
320322

321323
/**
322-
* @return Resque\Job\FactoryInterface
324+
* @return \Resque\Job\FactoryInterface
323325
*/
324326
public function getJobFactory()
325327
{

lib/Redis.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@
1414
* @package Resque/Redis
1515
* @author Chris Boulton <[email protected]>
1616
* @license http://www.opensource.org/licenses/mit-license.php
17+
*
18+
* @mixin Credis_Cluster
19+
* @method string get(string $key)
20+
* @method bool exists(string $key)
21+
* @method array smembers(string $set)
22+
* @method bool sismember(string $set, string $key)
23+
* @method bool del(string $key)
24+
* @method void set(string $key, mixed $value)
25+
* @method bool expire(string $key, string $key2)
26+
* @method bool ping(?string $value = null)
27+
* @method bool incrby(string $key, int $increment)
28+
* @method bool decrby(string $key, int $decrement)
29+
* @method bool rpush(string $key, string ...$element)
30+
* @method array blpop(string $key, int $timeout)
31+
* @method array lpop(string $key, int $count = 1)
32+
* @method array rpop(string $key, int $count = 1)
33+
* @method int llen(string $key)
34+
* @method array lrange(string $key, int $start, int $stop)
35+
* @method int rpoplpush(string $source, string $destination)
36+
* @method void zadd(string $key, int $score, string $member)
37+
* @method int zcard(string $key)
38+
* @method int sadd(string $key, string $member)
39+
* @method int srem(string $key, string $member)
40+
* @method int lrem(string $key, int $count, string $element)
41+
* @method array keys(string $pattern)
42+
* @method int zrem(string $key, string $member)
43+
* @method array zrangebyscore(string $key, int $min, int $max, bool $scores)
44+
1745
*/
1846
class Redis
1947
{
@@ -120,7 +148,7 @@ public static function prefix($namespace)
120148
}
121149

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

lib/Resque.php

Lines changed: 5 additions & 5 deletions
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 8 additions & 8 deletions
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)