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

JobConsume   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 18.18 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 63.16%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 10
loc 55
ccs 12
cts 19
cp 0.6316
rs 10
c 3
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 2
A handle() 0 10 2
A queueName() 0 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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