Test Failed
Push — master ( 6731a8...287bb0 )
by Hirofumi
08:50
created

DoctrineJobFlightManager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 66
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A departed() 0 5 1
A latestJobFlightOfJobId() 0 4 1
A acknowledged() 0 5 1
A abandoned() 0 5 1
A requeued() 0 7 1
A rejected() 0 5 1
A letGo() 0 5 1
1
<?php
2
3
namespace Shippinno\Job\Infrastructure\Application\Messaging;
4
5
use Doctrine\ORM\EntityRepository;
6
use Shippinno\Job\Application\Messaging\JobFlight;
7
use Shippinno\Job\Application\Messaging\JobFlightManager;
8
9
class DoctrineJobFlightManager extends EntityRepository implements JobFlightManager
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function departed(int $jobId, string $queue): void
15
    {
16
        $this->getEntityManager()->persist(new JobFlight($jobId, $queue));
17
        $this->getEntityManager()->flush();
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function latestJobFlightOfJobId(int $jobId): JobFlight
24
    {
25
        return $this->findOneBy(['jobId' => $jobId], ['id' => 'DESC']);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function acknowledged(int $jobId): void
32
    {
33
        $this->latestJobFlightOfJobId($jobId)->acknowledge();
34
        $this->getEntityManager()->flush();
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function abandoned(int $jobId): void
41
    {
42
        $this->latestJobFlightOfJobId($jobId)->abandoned();
43
        $this->getEntityManager()->flush();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function requeued(int $jobId): void
50
    {
51
        $jobFlight = $this->latestJobFlightOfJobId($jobId);
52
        $jobFlight->requeued();
53
        $this->departed($jobFlight->jobId(), $jobFlight->queue());
54
        $this->getEntityManager()->flush();
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function rejected(int $jobId): void
61
    {
62
        $this->latestJobFlightOfJobId($jobId)->rejected();
63
        $this->getEntityManager()->flush();
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function letGo(int $jobId): void
70
    {
71
        $this->latestJobFlightOfJobId($jobId)->letGo();
72
        $this->getEntityManager()->flush();
73
    }
74
}
75