1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Protocol\v091\Reader; |
5
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
7
|
|
|
Transport\Frame\Method, |
8
|
|
|
Transport\Frame\Visitor\Arguments, |
9
|
|
|
Transport\Frame\Value\ShortString, |
10
|
|
|
Transport\Frame\Value\UnsignedLongInteger, |
11
|
|
|
Transport\Protocol\v091\Methods, |
12
|
|
|
Exception\UnknownMethod |
13
|
|
|
}; |
14
|
|
|
use Innmind\Immutable\{ |
15
|
|
|
Str, |
16
|
|
|
StreamInterface |
17
|
|
|
}; |
18
|
|
|
|
19
|
|
View Code Duplication |
final class Queue |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @return StreamInterface<Value> |
|
|
|
|
23
|
|
|
*/ |
24
|
11 |
|
public function __invoke(Method $method, Str $arguments): StreamInterface |
25
|
|
|
{ |
26
|
|
|
switch (true) { |
27
|
11 |
|
case Methods::get('queue.declare-ok')->equals($method): |
|
|
|
|
28
|
2 |
|
$visit = $this->declareOk(); |
29
|
2 |
|
break; |
30
|
|
|
|
31
|
9 |
|
case Methods::get('queue.bind-ok')->equals($method): |
|
|
|
|
32
|
2 |
|
$visit = $this->bindOk(); |
33
|
2 |
|
break; |
34
|
|
|
|
35
|
7 |
|
case Methods::get('queue.unbind-ok')->equals($method): |
|
|
|
|
36
|
2 |
|
$visit = $this->unbindOk(); |
37
|
2 |
|
break; |
38
|
|
|
|
39
|
5 |
|
case Methods::get('queue.purge-ok')->equals($method): |
|
|
|
|
40
|
2 |
|
$visit = $this->purgeOk(); |
41
|
2 |
|
break; |
42
|
|
|
|
43
|
3 |
|
case Methods::get('queue.delete-ok')->equals($method): |
|
|
|
|
44
|
2 |
|
$visit = $this->deleteOk(); |
45
|
2 |
|
break; |
46
|
|
|
|
47
|
|
|
default: |
48
|
1 |
|
throw new UnknownMethod($method); |
49
|
|
|
} |
50
|
|
|
|
51
|
10 |
|
return $visit($arguments); |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
private function declareOk(): Arguments |
55
|
|
|
{ |
56
|
2 |
|
return new Arguments( |
57
|
2 |
|
ShortString::class, //queue |
58
|
2 |
|
UnsignedLongInteger::class, //message count |
59
|
2 |
|
UnsignedLongInteger::class //consumer count |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
2 |
|
private function bindOk(): Arguments |
64
|
|
|
{ |
65
|
2 |
|
return new Arguments; //no arguments |
66
|
|
|
} |
67
|
|
|
|
68
|
2 |
|
private function unbindOk(): Arguments |
69
|
|
|
{ |
70
|
2 |
|
return new Arguments; //no arguments |
71
|
|
|
} |
72
|
|
|
|
73
|
2 |
|
private function purgeOk(): Arguments |
74
|
|
|
{ |
75
|
2 |
|
return new Arguments( |
76
|
2 |
|
UnsignedLongInteger::class //message count |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
2 |
|
private function deleteOk(): Arguments |
81
|
|
|
{ |
82
|
2 |
|
return new Arguments( |
83
|
2 |
|
UnsignedLongInteger::class //message count |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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.