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\Bits, |
10
|
|
|
Transport\Frame\Value\ShortString, |
11
|
|
|
Transport\Frame\Value\UnsignedShortInteger, |
12
|
|
|
Transport\Protocol\v091\Methods, |
13
|
|
|
Exception\UnknownMethod |
14
|
|
|
}; |
15
|
|
|
use Innmind\Immutable\{ |
16
|
|
|
Str, |
17
|
|
|
StreamInterface |
18
|
|
|
}; |
19
|
|
|
|
20
|
|
View Code Duplication |
final class Channel |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @return StreamInterface<Value> |
|
|
|
|
24
|
|
|
*/ |
25
|
1 |
|
public function __invoke(Method $method, Str $arguments): StreamInterface |
26
|
|
|
{ |
27
|
|
|
switch (true) { |
28
|
1 |
|
case Methods::get('channel.open-ok')->equals($method): |
29
|
|
|
$visit = $this->openOk(); |
30
|
|
|
break; |
31
|
|
|
|
32
|
|
|
case Methods::get('channel.flow')->equals($method): |
33
|
|
|
$visit = $this->flow(); |
34
|
|
|
break; |
35
|
|
|
|
36
|
|
|
case Methods::get('channel.flow-ok')->equals($method): |
37
|
|
|
$visit = $this->flowOk(); |
38
|
|
|
break; |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
case Methods::get('channel.close')->equals($method): |
42
|
|
|
$visit = $this->close(); |
43
|
|
|
break; |
44
|
|
|
|
45
|
|
|
case Methods::get('channel.close-ok')->equals($method): |
46
|
|
|
$visit = $this->closeOk(); |
47
|
|
|
break; |
48
|
|
|
|
49
|
|
|
default: |
50
|
|
|
throw new UnknownMethod($method); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $visit($arguments); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function openOk(): Arguments |
57
|
|
|
{ |
58
|
|
|
return new Arguments; //no arguments |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function flow(): Arguments |
62
|
|
|
{ |
63
|
|
|
return new Arguments( |
64
|
|
|
Bits::class //active |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function flowOk(): Arguments |
69
|
|
|
{ |
70
|
|
|
return new Arguments( |
71
|
|
|
Bits::class //active |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function close(): Arguments |
76
|
|
|
{ |
77
|
|
|
return new Arguments( |
78
|
|
|
UnsignedShortInteger::class, //reply code |
79
|
|
|
ShortString::class, //reply text |
80
|
|
|
UnsignedShortInteger::class, //failing class id |
81
|
|
|
UnsignedShortInteger::class //failing method id |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
private function closeOk(): Arguments |
86
|
|
|
{ |
87
|
|
|
return new Arguments; // no arguments |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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.