1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Protocol\v091; |
5
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
7
|
|
|
Model\Queue\Declaration, |
8
|
|
|
Model\Queue\Deletion, |
9
|
|
|
Model\Queue\Binding, |
10
|
|
|
Model\Queue\Unbinding, |
11
|
|
|
Model\Queue\Purge, |
12
|
|
|
Transport\Frame, |
13
|
|
|
Transport\Frame\Channel as FrameChannel, |
14
|
|
|
Transport\Frame\Type, |
15
|
|
|
Transport\Frame\Value, |
16
|
|
|
Transport\Frame\Value\UnsignedShortInteger, |
17
|
|
|
Transport\Frame\Value\ShortString, |
18
|
|
|
Transport\Frame\Value\Bits, |
19
|
|
|
Transport\Frame\Value\Table, |
20
|
|
|
Transport\Protocol\Queue as QueueInterface |
21
|
|
|
}; |
22
|
|
|
use Innmind\Math\Algebra\Integer; |
23
|
|
|
use Innmind\Immutable\{ |
24
|
|
|
Str, |
25
|
|
|
Map |
26
|
|
|
}; |
27
|
|
|
|
28
|
|
|
final class Queue implements QueueInterface |
29
|
|
|
{ |
30
|
|
View Code Duplication |
public function declare(FrameChannel $channel, Declaration $command): Frame |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$name = ''; |
33
|
|
|
|
34
|
|
|
if (!$command->shouldAutoGenerateName()) { |
35
|
|
|
$name = $command->name(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return new Frame( |
39
|
|
|
Type::method(), |
40
|
|
|
$channel, |
41
|
|
|
Methods::get('queue.declare'), |
42
|
|
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
43
|
|
|
new ShortString(new Str($name)), |
44
|
|
|
new Bits($command->isPassive()), |
45
|
|
|
new Bits($command->isDurable()), |
46
|
|
|
new Bits($command->isExclusive()), |
47
|
|
|
new Bits($command->isAutoDeleted()), |
48
|
|
|
new Bits(!$command->shouldWait()), |
49
|
|
|
new Table(new Map('string', Value::class)) //todo: use $command->arguments() |
|
|
|
|
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function delete(FrameChannel $channel, Deletion $command): Frame |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
return new Frame( |
56
|
|
|
Type::method(), |
57
|
|
|
$channel, |
58
|
|
|
Methods::get('queue.delete'), |
59
|
|
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
60
|
|
|
new ShortString(new Str($command->name())), |
61
|
|
|
new Bits($command->onlyIfUnused()), |
62
|
|
|
new Bits($command->onlyIfEmpty()), |
63
|
|
|
new Bits(!$command->shouldWait()) |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
public function bind(FrameChannel $channel, Binding $command): Frame |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
return new Frame( |
70
|
|
|
Type::method(), |
71
|
|
|
$channel, |
72
|
|
|
Methods::get('queue.bind'), |
73
|
|
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
74
|
|
|
new ShortString(new Str($command->queue())), |
75
|
|
|
new ShortString(new Str($command->exchange())), |
76
|
|
|
new ShortString(new Str($command->routingKey())), |
77
|
|
|
new Bits(!$command->shouldWait()), |
78
|
|
|
new Table(new Map('string', Value::class)) //todo: use $command->arguments() |
|
|
|
|
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
public function unbind(FrameChannel $channel, Unbinding $command): Frame |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
return new Frame( |
85
|
|
|
Type::method(), |
86
|
|
|
$channel, |
87
|
|
|
Methods::get('queue.unbind'), |
88
|
|
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
89
|
|
|
new ShortString(new Str($command->queue())), |
90
|
|
|
new ShortString(new Str($command->exchange())), |
91
|
|
|
new ShortString(new Str($command->routingKey())), |
92
|
|
|
new Table(new Map('string', Value::class)) //todo: use $command->arguments() |
|
|
|
|
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
View Code Duplication |
public function purge(FrameChannel $channel, Purge $command): Frame |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
return new Frame( |
99
|
|
|
Type::method(), |
100
|
|
|
$channel, |
101
|
|
|
Methods::get('queue.purge'), |
102
|
|
|
new UnsignedShortInteger(new Integer(0)), //ticket (reserved) |
103
|
|
|
new ShortString(new Str($command->name())), |
104
|
|
|
new Bits(!$command->shouldWait()) |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.