Code Duplication    Length = 28-31 lines in 2 locations

src/TreeHouse/WorkerBundle/Queue.php 1 location

@@ 310-340 (lines=31) @@
307
     *
308
     * @return Job The next job for the given state, or null if there is no next job
309
     */
310
    public function peek($action, $state = 'ready')
311
    {
312
        if (false === $this->executorPool->hasExecutor($action)) {
313
            throw new InvalidArgumentException(
314
                sprintf(
315
                    'Action "%s" is not defined in QueueManager',
316
                    $action
317
                )
318
            );
319
        }
320
321
        $states = ['ready', 'delayed', 'buried'];
322
323
        if (!in_array($state, $states)) {
324
            throw new InvalidArgumentException(
325
                sprintf('$state must be one of %s, got %s', json_encode($states), json_encode($state))
326
            );
327
        }
328
329
        $peekMethod = sprintf('peek%s', ucfirst($state));
330
331
        try {
332
            return $this->pheanstalk->$peekMethod($action);
333
        } catch (Exception $exception) {
334
            if (false !== strpos($exception->getMessage(), 'NOT_FOUND')) {
335
                return null;
336
            }
337
338
            throw $exception;
339
        }
340
    }
341
342
    /**
343
     * Permanently deletes a job.

src/TreeHouse/WorkerBundle/QueueManager.php 1 location

@@ 394-421 (lines=28) @@
391
     *
392
     * @return Job The next job for the given state, or null if there is no next job
393
     */
394
    public function peek($action, $state = 'ready')
395
    {
396
        if (false === $this->hasExecutor($action)) {
397
            throw new \InvalidArgumentException(sprintf(
398
                'Action "%s" is not defined in QueueManager',
399
                $action
400
            ));
401
        }
402
403
        $states = ['ready', 'delayed', 'buried'];
404
        if (!in_array($state, $states)) {
405
            throw new \InvalidArgumentException(
406
                sprintf('$state must be one of %s, got %s', json_encode($states), json_encode($state))
407
            );
408
        }
409
410
        $peekMethod = sprintf('peek%s', ucfirst($state));
411
412
        try {
413
            return $this->pheanstalk->$peekMethod($action);
414
        } catch (Exception $exception) {
415
            if (false !== strpos($exception->getMessage(), 'NOT_FOUND')) {
416
                return null;
417
            }
418
419
            throw $exception;
420
        }
421
    }
422
423
    /**
424
     * Permanently deletes a job.