Completed
Push — master ( eff446...e0c858 )
by Adam
12:41
created

Event::shutdown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Equip\Queue;
4
5
use Equip\Command\OptionsInterface;
6
use Exception;
7
use League\Event\EmitterInterface;
8
use Psr\Log\LoggerInterface;
9
10
class Event
11
{
12
    const MESSAGE_ACKNOWLEDGE = 'message.acknowledge';
13
    const MESSAGE_FINISH = 'message.finish';
14
    const MESSAGE_REJECT = 'message.reject';
15
    const QUEUE_SHUTDOWN = 'queue.shutdown';
16
    const QUEUE_DRAINED = 'queue.drained';
17
18
    /**
19
     * @var EmitterInterface
20
     */
21
    private $emitter;
22
23
    /**
24
     * @var LoggerInterface
25
     */
26
    protected $logger;
27
28
    /**
29
     * @param EmitterInterface $emitter
30
     * @param LoggerInterface $logger
31
     */
32 5
    public function __construct(EmitterInterface $emitter, LoggerInterface $logger)
33
    {
34 5
        $this->emitter = $emitter;
35 5
        $this->logger = $logger;
36 5
    }
37
38
    /**
39
     * Emits message acknowledgement events
40
     *
41
     * @param object $command
42
     */
43 1
    public function acknowledge($command)
44
    {
45 1
        $this->emitter->emit(static::MESSAGE_ACKNOWLEDGE, $command);
0 ignored issues
show
Unused Code introduced by
The call to EmitterInterface::emit() has too many arguments starting with $command.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
46 1
        $this->logger->info(sprintf('`%s` job started', get_class($command->command())));
47 1
    }
48
49
    /**
50
     * Emits message finished events
51
     *
52
     * @param object $command
53
     */
54 1
    public function finish($command)
55
    {
56 1
        $this->emitter->emit(static::MESSAGE_FINISH, $command);
0 ignored issues
show
Unused Code introduced by
The call to EmitterInterface::emit() has too many arguments starting with $command.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
57 1
        $this->logger->info(sprintf('`%s` job finished', get_class($command->command())));
58 1
    }
59
60
    /**
61
     * Emits message rejection events
62
     *
63
     * @param object $command
64
     * @param Exception $exception
65
     */
66 1
    public function reject($command, Exception $exception)
67
    {
68 1
        $this->emitter->emit(static::MESSAGE_REJECT, $command, $exception);
0 ignored issues
show
Unused Code introduced by
The call to EmitterInterface::emit() has too many arguments starting with $command.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
69 1
        $this->logger->error($exception->getMessage());
70 1
    }
71
72
    /**
73
     * Handles notifications for shutting down
74
     */
75 1
    public function shutdown()
76
    {
77 1
        $this->emitter->emit(static::QUEUE_SHUTDOWN);
78 1
        $this->logger->notice('Shutting down');
79 1
    }
80
81
    /**
82
     * Handles notifications for shutting down when drained
83
     */
84 1
    public function drained()
85
    {
86 1
        $this->emitter->emit(static::QUEUE_DRAINED);
87 1
        $this->logger->notice('Drained - Shutting down');
88 1
    }
89
}
90