22
33namespace Resque ;
44
5- use InvalidArgumentException ;
65use Resque \Job \PID ;
76use Resque \Job \Status ;
87use Resque \Exceptions \DoNotPerformException ;
98use Resque \Job \FactoryInterface ;
109use Resque \Job \Factory ;
10+ use Resque \Job \Job ;
1111use Error ;
1212
1313/**
@@ -50,7 +50,7 @@ class JobHandler
5050 public $ endTime ;
5151
5252 /**
53- * @var object|\Resque\ Job\JobInterface Instance of the class performing work for this job.
53+ * @var Job Instance of the class performing work for this job.
5454 */
5555 private $ instance ;
5656
@@ -83,19 +83,13 @@ public function __construct($queue, $payload)
8383 * @param string $prefix The prefix needs to be set for the status key
8484 *
8585 * @return string
86- * @throws \InvalidArgumentException
8786 */
88- public static function create ($ queue , $ class , $ args = null , $ monitor = false , $ id = null , $ prefix = "" )
87+ public static function create ($ queue , $ class , array $ args = [] , $ monitor = false , $ id = null , $ prefix = "" )
8988 {
9089 if (is_null ($ id )) {
9190 $ id = Resque::generateJobId ();
9291 }
9392
94- if ($ args !== null && !is_array ($ args )) {
95- throw new InvalidArgumentException (
96- 'Supplied $args must be an array. '
97- );
98- }
9993 Resque::push ($ queue , array (
10094 'class ' => $ class ,
10195 'args ' => array ($ args ),
@@ -183,7 +177,7 @@ public function getStatus()
183177 *
184178 * @return array Array of arguments.
185179 */
186- public function getArguments ()
180+ public function getArguments (): array
187181 {
188182 if (!isset ($ this ->payload ['args ' ])) {
189183 return array ();
@@ -194,10 +188,10 @@ public function getArguments()
194188
195189 /**
196190 * Get the instantiated object for this job that will be performing work.
197- * @return \Resque\Job\JobInterface Instance of the object that this job belongs to.
191+ * @return \Resque\Job\Job Instance of the object that this job belongs to.
198192 * @throws \Resque\Exceptions\ResqueException
199193 */
200- public function getInstance ()
194+ public function getInstance (): Job
201195 {
202196 if (!is_null ($ this ->instance )) {
203197 return $ this ->instance ;
@@ -212,9 +206,8 @@ public function getInstance()
212206 * Actually execute a job by calling the perform method on the class
213207 * associated with the job with the supplied arguments.
214208 *
215- * @return bool
216- * @throws Resque\Exceptions\ResqueException When the job's class could not be found
217- * or it does not contain a perform method.
209+ * @return mixed
210+ * @throws Resque\Exceptions\ResqueException When the job's class could not be found.
218211 */
219212 public function perform ()
220213 {
@@ -225,15 +218,12 @@ public function perform()
225218 $ this ->startTime = microtime (true );
226219
227220 $ instance = $ this ->getInstance ();
228- if (is_callable ([$ instance , 'setUp ' ])) {
229- $ instance ->setUp ();
230- }
221+
222+ $ instance ->setUp ();
231223
232224 $ result = $ instance ->perform ();
233225
234- if (is_callable ([$ instance , 'tearDown ' ])) {
235- $ instance ->tearDown ();
236- }
226+ $ instance ->tearDown ();
237227
238228 $ this ->endTime = microtime (true );
239229
@@ -343,7 +333,7 @@ public function setJobFactory(FactoryInterface $jobFactory)
343333 /**
344334 * @return Resque\Job\FactoryInterface
345335 */
346- public function getJobFactory ()
336+ public function getJobFactory (): FactoryInterface
347337 {
348338 if ($ this ->jobFactory === null ) {
349339 $ this ->jobFactory = new Factory ();
0 commit comments