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

JobEnqueueSingle::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 0
cts 10
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 1
nop 3
crap 6
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