Test Failed
Push — master ( bf1804...12692f )
by Hirofumi
03:59
created

JobConsume::queueName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2.032
1
<?php
2
3
namespace Shippinno\Job\Infrastructure\Ui\Console\Laravel\Command;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Illuminate\Console\Command;
7
use LogicException;
8
use Psr\Log\LoggerAwareTrait;
9
use Psr\Log\LoggerInterface;
10
use Psr\Log\NullLogger;
11
use Shippinno\Job\Application\Messaging\ConsumeStoredJobService;
12
use Shippinno\Job\Infrastructure\Persistence\Doctrine\ManagerRegistryAwareTrait;
13
14
class JobConsume extends Command
15
{
16
    use ManagerRegistryAwareTrait;
17
    use LoggerAwareTrait;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    protected $signature = 'job:consume';
23
24
    /**
25
     * @var ConsumeStoredJobService
26
     */
27
    private $consumeStoredJobService;
28
29
    /**
30
     * @param ConsumeStoredJobService $consumeStoredJobService
31
     * @param ManagerRegistry|null $managerRegistry
32
     * @param LoggerInterface|null $logger
33
     */
34 1 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
        ConsumeStoredJobService $consumeStoredJobService,
36
        ManagerRegistry $managerRegistry = null,
37
        LoggerInterface $logger = null
38
    ) {
39 1
        parent::__construct();
40 1
        $this->consumeStoredJobService = $consumeStoredJobService;
41 1
        $this->setManagerRegistry($managerRegistry);
42 1
        $this->setLogger(null !== $logger ? $logger : new NullLogger);
43 1
    }
44
45 1
    public function handle()
46
    {
47 1
        $queueName = $this->queueName();
48
        $forever = !env('JOB_TESTING', false);
49
        do {
50
            $this->clear();
51
            $this->consumeStoredJobService->execute($queueName);
52
            $this->flush();
53
        } while ($forever);
54
    }
55
56
    /**
57
     * @return string
58
     */
59 1
    private function queueName(): string
60
    {
61 1
        $queueName = env('JOB_CONSUME_QUEUE');
62 1
        if (!$queueName) {
63 1
            throw new LogicException('The env JOB_CONSUME_QUEUE is not defined');
64
        }
65
66
        return $queueName;
67
    }
68
}
69