Controller   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 48
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getJobs() 0 10 2
A deleteJob() 0 6 1
1
<?php
2
3
namespace BrainExe\Core\MessageQueue;
4
5
use BrainExe\Core\Annotations\Controller as ControllerAnnotation;
6
use BrainExe\Core\Annotations\Route;
7
use BrainExe\Core\MessageQueue\Gateway as MessageQueueGateway;
8
use BrainExe\Core\Traits\TimeTrait;
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * @ControllerAnnotation
13
 */
14
class Controller
15
{
16
    use TimeTrait;
17
18
    /**
19
     * @var MessageQueueGateway
20
     */
21
    private $gateway;
22
23
    /**
24
     * @param MessageQueueGateway $gateway
25
     */
26 2
    public function __construct(MessageQueueGateway $gateway)
27
    {
28 2
        $this->gateway = $gateway;
29 2
    }
30
31
    /**
32
     * @Route("/jobs/{type}/", name="status.jobs.type", methods="GET")
33
     * @param Request $request
34
     * @param string $type
35
     * @return Job[]
36
     */
37 1
    public function getJobs(Request $request, string $type) : array
38
    {
39 1
        $since = 0;
40
41 1
        if ($request->query->getInt('futureOnly')) {
42 1
            $since = $this->now();
43
        }
44
45 1
        return $this->gateway->getEventsByType($type, $since);
46
    }
47
48
    /**
49
     * @Route("/jobs/{eventId}:{jobId}/", methods="DELETE", name="messageQueue.deleteJob", requirements={"jobId":"\d+"})
50
     * @param Request $request
51
     * @param string $eventType
52
     * @param int $jobId
53
     * @return bool
54
     */
55 1
    public function deleteJob(Request $request, string $eventType, int $jobId) : bool
56
    {
57 1
        unset($request);
58
59 1
        return $this->gateway->deleteEvent($jobId, $eventType);
60
    }
61
}
62