Event::reject()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
1
<?php
2
3
namespace Equip\Queue;
4
5
use Exception;
6
use League\Event\EmitterInterface;
7
use Psr\Log\LoggerInterface;
8
9
class Event
10
{
11
    const MESSAGE_ACKNOWLEDGE = 'message.acknowledge';
12
    const MESSAGE_FINISH = 'message.finish';
13
    const MESSAGE_REJECT = 'message.reject';
14
    const QUEUE_SHUTDOWN = 'queue.shutdown';
15
    const QUEUE_DRAINED = 'queue.drained';
16
17
    /**
18
     * @var EmitterInterface
19
     */
20
    private $emitter;
21
22
    /**
23
     * @var LoggerInterface
24
     */
25
    protected $logger;
26
27
    /**
28
     * @param EmitterInterface $emitter
29
     * @param LoggerInterface $logger
30
     */
31 5
    public function __construct(EmitterInterface $emitter, LoggerInterface $logger)
32
    {
33 5
        $this->emitter = $emitter;
34 5
        $this->logger = $logger;
35 5
    }
36
37
    /**
38
     * Emits message acknowledgement events
39
     *
40
     * @param object $command
41
     */
42 1
    public function acknowledge($command)
43
    {
44 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...
45 1
        $this->logger->info(sprintf('`%s` job started', get_class($command->command())));
46 1
    }
47
48
    /**
49
     * Emits message finished events
50
     *
51
     * @param object $command
52
     */
53 1
    public function finish($command)
54
    {
55 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...
56 1
        $this->logger->info(sprintf('`%s` job finished', get_class($command->command())));
57 1
    }
58
59
    /**
60
     * Emits message rejection events
61
     *
62
     * @param object $command
63
     * @param Exception $exception
64
     */
65 1
    public function reject($command, Exception $exception)
66
    {
67 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...
68 1
        $this->logger->error($exception->getMessage(), compact('exception'));
69 1
    }
70
71
    /**
72
     * Handles notifications for shutting down
73
     */
74 1
    public function shutdown()
75
    {
76 1
        $this->emitter->emit(static::QUEUE_SHUTDOWN);
77 1
        $this->logger->notice('Shutting down');
78 1
    }
79
80
    /**
81
     * Handles notifications for shutting down when drained
82
     */
83 1
    public function drained()
84
    {
85 1
        $this->emitter->emit(static::QUEUE_DRAINED);
86 1
        $this->logger->notice('Drained - Shutting down');
87 1
    }
88
}
89