Total Complexity | 6 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
19 | final class Consume implements Command |
||
20 | { |
||
21 | private $client; |
||
22 | private $consumers; |
||
23 | |||
24 | 7 | public function __construct(Client $client, Consumers $consumers) |
|
28 | 7 | } |
|
29 | |||
30 | 4 | public function __invoke(Environment $env, Arguments $arguments, Options $options): void |
|
31 | { |
||
32 | 4 | $queue = $arguments->get('queue'); |
|
33 | 4 | $consume = $this->consumers->get($queue); |
|
34 | 4 | $basic = $this->client->channel()->basic(); |
|
35 | |||
36 | 4 | if ($arguments->contains('prefetch')) { |
|
37 | 1 | $basic->qos(new Qos(0, (int) $arguments->get('prefetch'))); |
|
38 | 3 | } else if ($arguments->contains('number')) { |
|
39 | 1 | $basic->qos(new Qos(0, (int) $arguments->get('number'))); |
|
40 | } |
||
41 | |||
42 | 4 | $consumer = $basic->consume(new Basic\Consume($queue)); |
|
43 | |||
44 | 4 | if ($arguments->contains('number')) { |
|
45 | 2 | $consumer->take((int) $arguments->get('number')); |
|
46 | } |
||
47 | |||
48 | try { |
||
49 | 4 | $consumer->foreach($consume); |
|
50 | 3 | } finally { |
|
51 | 4 | $this->client->close(); |
|
52 | } |
||
53 | 3 | } |
|
54 | |||
55 | 1 | public function __toString(): string |
|
58 | 1 | innmind:amqp:consume queue [number] [prefetch] |
|
59 | |||
64 |