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
|
|
|
|
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
|
3 |
|
public function __construct(EmitterInterface $emitter, LoggerInterface $logger) |
32
|
|
|
{ |
33
|
3 |
|
$this->emitter = $emitter; |
34
|
3 |
|
$this->logger = $logger; |
35
|
3 |
|
} |
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); |
|
|
|
|
45
|
1 |
|
$this->logger->info(sprintf('`%s` job started', get_class($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); |
|
|
|
|
56
|
1 |
|
$this->logger->info(sprintf('`%s` job finished', get_class($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); |
|
|
|
|
68
|
1 |
|
$this->logger->error($exception->getMessage()); |
69
|
1 |
|
} |
70
|
|
|
} |
71
|
|
|
|
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.