Test Failed
Push — master ( 0bbeee...5fd70b )
by Hirofumi
02:10
created

JobConsume   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 18.87 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 87.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 10
loc 53
c 2
b 0
f 0
wmc 7
lcom 1
cbo 6
rs 10
ccs 7
cts 8
cp 0.875

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 2
B handle() 0 17 5

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 Interop\Queue\PsrContext;
8
use LogicException;
9
use Psr\Log\LoggerAwareTrait;
10
use Psr\Log\LoggerInterface;
11
use Psr\Log\NullLogger;
12
use Shippinno\Job\Application\Messaging\ConsumeStoredJobService;
13
use Shippinno\Job\Domain\Model\JobRunnerNotRegisteredException;
14
15
class JobConsume extends Command
16
{
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
     * @var ManagerRegistry|null
31
     */
32
    private $managerRegistry;
33
34
    /**
35
     * @param ConsumeStoredJobService $consumeStoredJobService
36
     * @param ManagerRegistry|null $managerRegistry
37
     * @param LoggerInterface|null $logger
38
     */
39 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...
40
        ConsumeStoredJobService $consumeStoredJobService,
41
        ManagerRegistry $managerRegistry = null,
42
        LoggerInterface $logger = null
43
    ) {
44
        parent::__construct();
45
        $this->consumeStoredJobService = $consumeStoredJobService;
46
        $this->managerRegistry = $managerRegistry;
47
        $this->setLogger(null !== $logger ? $logger : new NullLogger);
48 3
    }
49
50
    public function handle()
51
    {
52
        $queueName = env('JOB_CONSUME_QUEUE');
53
        if (!$queueName) {
54 3
            throw new LogicException('The env JOB_CONSUME_QUEUE is not defined');
55 3
        }
56 3
        $forever = !env('JOB_TESTING', false);
57 3
        do {
58 3
            if (null !== $this->managerRegistry) {
59 3
                $this->managerRegistry->getManager()->clear();
60
            }
61
            $this->consumeStoredJobService->execute($queueName);
62
            if (null !== $this->managerRegistry) {
63
                $this->managerRegistry->getManager()->flush();
64
            }
65
        } while ($forever);
66
    }
67
}
68