1 | <?php |
||
10 | class Settings |
||
11 | { |
||
12 | //(int) in bytes (default system) |
||
|
|||
13 | const PARAM_MAX_MESSAGE_SIZE = 'PARAM_MAX_MESSAGE_SIZE'; |
||
14 | //(int) max send retry time, default DEFAULT_RETRY_TIMES |
||
15 | const PARAM_MAX_SEND_RETRY_TIME = 'PARAM_MAX_SEND_RETRY_TIME'; |
||
16 | const PARAM_CONSUMER_NAME = 'PARAM_CONSUMER_NAME';//(string) define consumer name - default empty |
||
17 | |||
18 | //(bool) if process must wait to be sure the message is sent (default false) |
||
19 | const PARAM_BLOCK_SEND = 'PARAM_BLOCK_SEND'; |
||
20 | //(bool) process will be blocked while no message is received (default false) |
||
21 | const PARAM_BLOCK_RECEIVE = 'PARAM_BLOCK_RECEIVE'; |
||
22 | //(bool) must serialize a message (default true) |
||
23 | const PARAM_SERIALIZE = 'PARAM_SERIALIZE'; |
||
24 | const PARAM_AUTO_ACK = 'PARAM_AUTO_ACK'; //(bool) must ack a message as soon as it is retrieved (default false) |
||
25 | |||
26 | const DEFAULT_RETRY_TIMES = 3; |
||
27 | |||
28 | const FLAG_BLOCK_SEND = 1; |
||
29 | const FLAG_BLOCK_RECEIVE = 2; |
||
30 | const FLAG_SERIALIZE = 4; |
||
31 | const FLAG_AUTO_ACK = 8; |
||
32 | |||
33 | private $settings = array(); |
||
34 | private $consumerName = ''; |
||
35 | private $flags = self::FLAG_SERIALIZE; |
||
36 | |||
37 | /** |
||
38 | * @param array $settings |
||
39 | */ |
||
40 | 14 | public function __construct(array $settings = array()) |
|
44 | |||
45 | /** |
||
46 | * Define multiple settings by a single array |
||
47 | * @param array $settings |
||
48 | * @return $this |
||
49 | * @throws QueueException |
||
50 | */ |
||
51 | 14 | public function defineByArray(array $settings) |
|
52 | { |
||
53 | 14 | foreach ($settings as $setting => $value) { |
|
54 | 4 | $this->define($setting, $value); |
|
55 | } |
||
56 | 12 | return $this; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Define a single setting by its name |
||
61 | * @param string $setting |
||
62 | * @param mixed $value |
||
63 | * @return $this |
||
64 | * @throws QueueException |
||
65 | */ |
||
66 | 3 | public function define($setting, $value) |
|
67 | { |
||
68 | switch ($setting) { |
||
69 | 3 | case self::PARAM_MAX_MESSAGE_SIZE: |
|
70 | 1 | $this->setMaxMessageSize($value); |
|
71 | 1 | break; |
|
72 | 3 | case self::PARAM_BLOCK_SEND: |
|
73 | 1 | $this->setBlockSend($value); |
|
74 | 1 | break; |
|
75 | 3 | case self::PARAM_SERIALIZE: |
|
76 | 1 | $this->setSerialize($value); |
|
77 | 1 | break; |
|
78 | 3 | case self::PARAM_BLOCK_RECEIVE: |
|
79 | 1 | $this->setBlockReceive($value); |
|
80 | 1 | break; |
|
81 | 3 | case self::PARAM_MAX_SEND_RETRY_TIME: |
|
82 | 1 | $this->setMaxSendRetryTime($value); |
|
83 | 1 | break; |
|
84 | 3 | case self::PARAM_AUTO_ACK: |
|
85 | 1 | $this->setAutoAck($value); |
|
86 | 1 | break; |
|
87 | 3 | case self::PARAM_CONSUMER_NAME: |
|
88 | 1 | $this->setConsumerName($value); |
|
89 | 1 | break; |
|
90 | default: |
||
91 | 2 | throw new QueueException('Setting is not defined'); |
|
92 | break; |
||
93 | } |
||
94 | 1 | return $this; |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * Define consumer name |
||
99 | * @param string $consumerName |
||
100 | * @return $this |
||
101 | */ |
||
102 | 1 | public function setConsumerName($consumerName = '') |
|
107 | |||
108 | /** |
||
109 | * Retrieve defined consumer name |
||
110 | * @return string |
||
111 | */ |
||
112 | 1 | public function getConsumerName() |
|
116 | |||
117 | /** |
||
118 | * Define max message size (default system) |
||
119 | * @param int $size |
||
120 | * @return $this |
||
121 | */ |
||
122 | 4 | public function setMaxMessageSize($size = 0) |
|
127 | |||
128 | /** |
||
129 | * Get max message size (default system) |
||
130 | * @return int |
||
131 | */ |
||
132 | 3 | public function getMaxMessageSize() |
|
138 | |||
139 | /** |
||
140 | * Define if process must wait to be sure the message is sent (default false) |
||
141 | * @param bool|false $blockSend |
||
142 | * @return $this |
||
143 | */ |
||
144 | 3 | public function setBlockSend($blockSend = false) |
|
149 | |||
150 | /** |
||
151 | * Get if process must wait to be sure the message is sent (default false) |
||
152 | * @return bool |
||
153 | */ |
||
154 | 3 | public function getBlockSend() |
|
158 | |||
159 | /** |
||
160 | * Define if process must serialize a message (default true) |
||
161 | * @param bool|true $serialize |
||
162 | * @return $this |
||
163 | */ |
||
164 | 3 | public function setSerialize($serialize = true) |
|
169 | |||
170 | /** |
||
171 | * Get if process must serialize a message (default true) |
||
172 | * @return bool |
||
173 | */ |
||
174 | 5 | public function getSerialize() |
|
178 | |||
179 | /** |
||
180 | * Define if process will be blocked while no message is received (default false) |
||
181 | * @param bool|false $blockReceive |
||
182 | * @return $this |
||
183 | */ |
||
184 | 3 | public function setBlockReceive($blockReceive = false) |
|
191 | |||
192 | /** |
||
193 | * Get if process will be blocked while no message is received (default false) |
||
194 | * @return bool |
||
195 | */ |
||
196 | 3 | public function getBlockReceive() |
|
200 | |||
201 | /** |
||
202 | * Define if message are auto ack-ed (default false) |
||
203 | * @param bool|false $autoAck |
||
204 | * @return $this |
||
205 | */ |
||
206 | 2 | public function setAutoAck($autoAck = false) |
|
211 | |||
212 | /** |
||
213 | * Get if message are auto acked on this channel |
||
214 | * @return bool |
||
215 | */ |
||
216 | 1 | public function getAutoAck() |
|
220 | |||
221 | /** |
||
222 | * Define max send retry time, default DEFAULT_RETRY_TIMES |
||
223 | * @param int $maxRetry |
||
224 | * @return $this |
||
225 | */ |
||
226 | 3 | public function setMaxSendRetryTime($maxRetry = 0) |
|
231 | |||
232 | /** |
||
233 | * Get max message size (default system) |
||
234 | * @return int |
||
235 | */ |
||
236 | 3 | public function getMaxSendRetryTime() |
|
242 | } |
||
243 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.