Test Failed
Push — master ( 7e0fa4...03f785 )
by Hirofumi
02:57
created

JobEnqueueSingle   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 18.87 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 10
loc 53
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 2
A handle() 0 4 1
A topicName() 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\EnqueueSingleStoredJobService;
12
use Shippinno\Job\Domain\Model\FailedToEnqueueStoredJobException;
13
use Shippinno\Job\Domain\Model\StoredJobNotFoundException;
14
use Shippinno\Job\Infrastructure\Persistence\Doctrine\ManagerRegistryAwareTrait;
15
16
class JobEnqueueSingle extends Command
17
{
18
    use ManagerRegistryAwareTrait;
19
    use LoggerAwareTrait;
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    protected $signature = 'job:enqueue:single {jobId}';
25
26
    /**
27
     * @var EnqueueSingleStoredJobService
28
     */
29
    private $service;
30
31
    /**
32
     * @param EnqueueSingleStoredJobService $service
33
     * @param ManagerRegistry|null $managerRegistry
34
     * @param LoggerInterface|null $logger
35
     */
36 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...
37
        EnqueueSingleStoredJobService $service,
38
        ManagerRegistry $managerRegistry = null,
39
        LoggerInterface $logger = null
40
    ) {
41
        parent::__construct();
42
        $this->service = $service;
43
        $this->setManagerRegistry($managerRegistry);
44
        $this->setLogger(null !== $logger ? $logger : new NullLogger);
45
    }
46
47
    /**
48
     * @throws FailedToEnqueueStoredJobException
49
     * @throws StoredJobNotFoundException
50
     */
51
    public function handle()
52
    {
53
        $this->service->execute($this->topicName(), intval($this->argument('jobId')));
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    private function topicName(): string
60
    {
61
        $topicName = env('JOB_ENQUEUE_TOPIC');
62
        if (!$topicName) {
63
            throw new LogicException('The env JOB_ENQUEUE_TOPIC is not defined');
64
        }
65
66
        return $topicName;
67
    }
68
}
69