Completed
Push — 1.0 ( 7ed330...095234 )
by David
02:56
created

Queue::setNoWait()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace Mouf\AmqpClient\Objects;
3
4
use Mouf\AmqpClient\RabbitMqObjectInterface;
5
use PhpAmqpLib\Channel\AMQPChannel;
6
7
/**
8
 * @author Marc
9
 *
10
 */
11
class Queue implements RabbitMqObjectInterface{
12
13
	/**
14
	 * 
15
	 * @var Binding
16
	 */
17
	private $source;
18
	
19
	/**
20
	 * Queue name
21
	 * @var String
22
	 */
23
	private $name;
24
	
25
	/**
26
	 * Queue
27
	 * @var string
28
	 */
29
	private $queue = '';
0 ignored issues
show
Unused Code introduced by
The property $queue is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
	
31
	/**
32
	 * Passive
33
	 * @var bool
34
	 */
35
	private $passive = false;
36
	
37
	/**
38
	 * Durable
39
	 * @var bool
40
	 */
41
	private $durable = false;
42
	
43
	/**
44
	 * Exclusive
45
	 * @var bool
46
	 */
47
	private $exclusive = false;
48
	
49
	/**
50
	 * Auto delete
51
	 * @var bool
52
	 */
53
	private $autoDelete = false;
54
	
55
	/**
56
	 * No wait
57
	 * @var bool
58
	 */
59
	private $autoDelete = false;
60
	
61
	/**
62
	 * Ticket
63
	 * @var int
64
	 */
65
	private $ticket = null;
66
	
67
	/**
68
	 *R abbitMq specific parameter : x-dead-letter-exchange
69
	 * @var Queue
70
	 */
71
	private $deadLetterQueue = null;
72
	
73
	/**
74
	 * RabbitMq specific parameter : confirm
75
	 * @var int
76
	 */
77
	private $confirm = null;
78
	
79
	/**
80
	 * RabbitMq specific parameter : consumer_cancel_notify 
81
	 * @var bool
82
	 */
83
	private $consumerCancelNotify = null;
84
	
85
	/**
86
	 * RabbitMq specific parameter : alternate-exchange 
87
	 * @var Queue
88
	 */
89
	private $alternateExchange = null;
90
	
91
	/**
92
	 * RabbitMq specific parameter : x-message-ttl 
93
	 * @var int
94
	 */
95
	private $ttl = null;
96
	
97
	/**
98
	 * RabbitMq specific parameter : x-max-length 
99
	 * @var int
100
	 */
101
	private $maxLength = null;
102
	
103
	/**
104
	 * RabbitMq specific parameter : x-max-priority 
105
	 * @var int
106
	 */
107
	private $maxPriority = null;
108
	
109
	/**
110
	 * Parameter to initialize object only one time
111
	 * @var bool
112
	 */
113
	private $init = false;
114
	
115
	/**
116
	 * Set the source (Binding)
117
	 * @param Binding $source
118
	 * @param string $name
119
	 */
120
	public function __contruct(Binding $source, $name) {
121
		$this->source = $source;
122
		$this->name = $name;
123
	}
124
125
	/**
126
	 * Get queue name
127
	 * @return string
128
	 */
129
	public function getName() {
130
		return $this->name;
131
	}
132
133
	/**
134
	 * Get passive
135
	 * @return bool
136
	 */
137
	public function getPassive() {
138
		return $this->passive;
139
	}
140
	
141
	/**
142
	 *
143
	 * @param bool $passive
144
	 * @return Queue
145
	 */
146
	public function setPassive($passive) {
147
		$this->passive = $passive;
148
		return $this;
149
	}
150
	
151
	/**
152
	 * Get durable
153
	 * @return bool
154
	 */
155
	public function getDurable() {
156
		return $this->durable;
157
	}
158
	
159
	/**
160
	 * Set durable
161
	 * @param bool $durable
162
	 * @return Queue
163
	 */
164
	public function setDurable($durable) {
165
		$this->durable = $durable;
166
		return $this;
167
	}
168
	
169
	/**
170
	 * Get exclusive
171
	 * @return bool
172
	 */
173
	public function getExclusive() {
174
		return $this->exclusive;
175
	}
176
	
177
	/**
178
	 * Set exclusive
179
	 * @param bool $exclusive
180
	 * @return Queue
181
	 */
182
	public function setExclusive($exclusive) {
183
		$this->exclusive = $exclusive;
184
		return $this;
185
	}
186
	
187
	/**
188
	 * Get autoDelete
189
	 * @return bool
190
	 */
191
	public function getAutoDelete() {
192
		return $this->autoDelete;
193
	}
194
	
195
	/**
196
	 * Set autoDelete
197
	 * @param bool $autoDelete
198
	 * @return Queue
199
	 */
200
	public function setAutoDelete($autoDelete) {
201
		$this->autoDelete = $autoDelete;
202
		return $this;
203
	}
204
	
205
	/**
206
	 * Get noWait
207
	 * @return bool
208
	 */
209
	public function getNoWait() {
210
		return $this->noWait;
0 ignored issues
show
Bug introduced by
The property noWait does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
211
	}
212
	
213
	/**
214
	 * Set noWait
215
	 * @param bool $noWait
216
	 * @return Queue
217
	 */
218
	public function setNoWait($noWait) {
219
		$this->noWait = $noWait;
220
		return $this;
221
	}
222
	
223
	/**
224
	 * Get arguments
225
	 * @return array|null
226
	 */
227
	public function getArguments() {
228
		return $this->arguments;
0 ignored issues
show
Bug introduced by
The property arguments does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
229
	}
230
	
231
	/**
232
	 * Set arguments
233
	 * @param array $arguments
234
	 * @return Queue
235
	 */
236
	public function setArguments($arguments) {
237
		$this->arguments = $arguments;
238
		return $this;
239
	}
240
	
241
	/**
242
	 * Get ticket
243
	 * @return int
244
	 */
245
	public function getTicket() {
246
		return $this->ticket;
247
	}
248
	
249
	/**
250
	 * Set ticket
251
	 * @param int $ticket
252
	 * @return Queue
253
	 */
254
	public function setTicket($ticket) {
255
		$this->ticket = $ticket;
256
		return $this;
257
	}
258
259
	/**
260
	 * Get RabbitMq specific parameter : dead letter queue
261
	 * @return Queue
262
	 */
263
	public function getDeadLetterQueue() {
264
		return $this->deadLetterQueue;
265
	}
266
	
267
	/**
268
	 * Set RabbitMq specific parameter : dead letter queue
269
	 * @param Queue $queue
270
	 * @return Queue
271
	 */
272
	public function setDeadLetterQueue(Queue $queue) {
273
		$this->deadLetterQueue = $queue;
274
		return $this;
275
	}
276
	
277
	/**
278
	 * Get RabbitMq specific parameter : confirm
279
	 * @return int
280
	 */
281
	public function getConfirm() {
282
		return $this->confirm;
283
	}
284
	
285
	/**
286
	 * Set RabbitMq specific parameter : confirm
287
	 * @param int $confirm
288
	 * @return Queue
289
	 */
290
	public function setConfirm($confirm) {
291
		$this->confirm = $confirm;
292
		return $this;
293
	}
294
	
295
	/**
296
	 * Get RabbitMq specific parameter : consumer_cancel_notify
297
	 * @return bool
298
	 */
299
	public function getConsumerCancelNotify() {
300
		return $this->consumerCancelNotify;
301
	}
302
	
303
	/**
304
	 * Set RabbitMq specific parameter : consumer_cancel_notify
305
	 * @param Queue $consumerCancelNotify
306
	 * @return Queue
307
	 */
308
	public function setConsumerCancelNotify(Queue $consumerCancelNotify) {
309
		$this->consumerCancelNotify = $consumerCancelNotify;
0 ignored issues
show
Documentation Bug introduced by
It seems like $consumerCancelNotify of type object<Mouf\AmqpClient\Objects\Queue> is incompatible with the declared type boolean of property $consumerCancelNotify.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
310
		return $this;
311
	}
312
	
313
	/**
314
	 * Get RabbitMq specific parameter : alternate_exchange
315
	 * @return Queue
316
	 */
317
	public function getAlternateExchange() {
318
		return $this->alternateExchange;
319
	}
320
	
321
	/**
322
	 * Set RabbitMq specific parameter : alternate_exchange
323
	 * @param Queue $alternateExchange
324
	 * @return Queue
325
	 */
326
	public function setAlternateExchange(Queue $alternateExchange) {
327
		$this->alternateExchange = $alternateExchange;
328
		return $this;
329
	}
330
	
331
	/**
332
	 * Get RabbitMq specific parameter : ttl
333
	 * @return int
334
	 */
335
	public function getTtl() {
336
		return $this->ttl;
337
	}
338
	
339
	/**
340
	 * Set RabbitMq specific parameter : ttl
341
	 * @param int $ttl
342
	 * @return Queue
343
	 */
344
	public function setTtl($ttl) {
345
		$this->ttl = $ttl;
346
		return $this;
347
	}
348
	
349
	/**
350
	 * Get RabbitMq specific parameter : max length
351
	 * @return int
352
	 */
353
	public function getMaxLength() {
354
		return $this->maxLength;
355
	}
356
	
357
	/**
358
	 * Set RabbitMq specific parameter : max length
359
	 * @param int $ttl
0 ignored issues
show
Bug introduced by
There is no parameter named $ttl. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
360
	 * @return Queue
361
	 */
362
	public function setMaxLength($maxLength) {
363
		$this->maxLength = $maxLength;
364
		return $this;
365
	}
366
	
367
	/**
368
	 * Get RabbitMq specific parameter : max priority
369
	 * @return int
370
	 */
371
	public function getMaxPriority() {
372
		return $this->maxPriority;
373
	}
374
	
375
	/**
376
	 * Set RabbitMq specific parameter : max priority
377
	 * @param int $maxPriority
378
	 * @return Queue
379
	 */
380
	public function setMaxPriority($maxPriority) {
381
		$this->maxPriority = $maxPriority;
382
		return $this;
383
	}
384
	
385
	
386
	public function init(AMQPChannel $amqpChannel) {
387
		if(!$this->init) {
388
			$this->source->init($amqpChannel);
389
			$this->deadLetterQueue->init($amqpChannel);
390
			
391
			$parameters = [];
392
			if($this->alternateExchange !== null) {
393
				$parameters['alternate-exchange'] = $this->alternateExchange->getName();
394
			}
395
			if($this->confirm !== null) {
396
				$parameters['confirm'] = $this->confirm;
397
			}
398
			if($this->consumerCancelNotify !== null) {
399
				$parameters['consumer_cancel_notify'] = $this->consumerCancelNotify;
400
			}
401
			if($this->deadLetterQueue !== null) {
402
				$parameters['x-dead-letter-exchange'] = $this->deadLetterQueue->getName();
403
			}
404
			if($this->maxLength) {
405
				$parameters['x-max-length'] = $this->maxLength;
406
			}
407
			if($this->maxPriority) {
408
				$parameters['x-max-priority'] = $this->maxPriority;
409
			}
410
			if($this->ttl) {
411
				$parameters['x-message-ttl'] = $this->ttl;
412
			}
413
			
414
			if(!$parameters) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $parameters of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
415
				$parameters = null;
416
			}
417
			$amqpChannel->queue_declare($this->name, $this->passive, $this->durable, $this->exclusive, $this->autoDelete, $this->noWait, $parameters);
418
			
419
			$this->init = true;
420
		}
421
	}
422
423
424
	public function comsume() {
425
	
426
	}
427
}