Completed
Pull Request — master (#1)
by Daniel
12:19
created

WorkerQueueBag::getPassive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Transport\Worker;
4
5
use Cmobi\RabbitmqBundle\Queue\QueueBagInterface;
6
7 View Code Duplication
class WorkerQueueBag implements QueueBagInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
8
{
9
    private $options;
10
11
    public function __construct(
12
        $queue,
13
        $basicQos = 1,
14
        $passive = false,
15
        $durable = true,
16
        $exclusive = false,
17
        $autoDelete = false,
18
        $noWait = false,
19
        array $arguments = null,
20
        $ticket = null,
21
        $consumerTag = '',
22
        $noAck = false,
23
        $noLocal = false
24
    )
25
    {
26
        $this->options = [
27
            'queue' => $queue,
28
            'basic_qos' => $basicQos,
29
            'passive' => $passive,
30
            'durable' => $durable,
31
            'exclusive' => $exclusive,
32
            'auto_delete' => $autoDelete,
33
            'no_wait' => $noWait,
34
            'arguments' => $arguments,
35
            'ticket' => $ticket,
36
            'consumer_tag' => $consumerTag,
37
            'no_ack' => $noAck,
38
            'no_local' => $noLocal
39
        ];
40
    }
41
42
    /**
43
     * @param $queue
44
     */
45
    public function setQueue($queue)
46
    {
47
        $this->options['queue'] = $queue;
48
    }
49
50
    /**
51
     * @return string|mixed
52
     */
53
    public function getQueue()
54
    {
55
        return $this->options['queue'];
56
    }
57
58
    /**
59
     * @param $qos
60
     */
61
    public function setBasicQos($qos)
62
    {
63
        $this->options['basic_qos'] = $qos;
64
    }
65
66
    /**
67
     * @return int
68
     */
69
    public function getBasicQos()
70
    {
71
        return $this->options['basic_qos'];
72
    }
73
74
    /**
75
     * @param $passive
76
     */
77
    public function setPassive($passive)
78
    {
79
        $this->options['passive'] = $passive;
80
    }
81
82
    /**
83
     * @return bool
84
     */
85
    public function getPassive()
86
    {
87
        return $this->options['passive'];
88
    }
89
90
    /**
91
     * @param $durable
92
     */
93
    public function setDurable($durable)
94
    {
95
        $this->options['durable'] = $durable;
96
    }
97
98
    /**
99
     * @return bool
100
     */
101
    public function getDurable()
102
    {
103
        return $this->options['durable'];
104
    }
105
106
    /**
107
     * @param $exclusive
108
     */
109
    public function setExclusive($exclusive)
110
    {
111
        $this->options['exclusive'] = $exclusive;
112
    }
113
114
    /**
115
     * @return bool
116
     */
117
    public function getExclusive()
118
    {
119
        return $this->options['exclusive'];
120
    }
121
122
    /**
123
     * @param $autoDelete
124
     */
125
    public function setAutoDelete($autoDelete)
126
    {
127
        $this->options['auto_delete'] = $autoDelete;
128
    }
129
130
    /**
131
     * @return bool
132
     */
133
    public function getAutoDelete()
134
    {
135
        return $this->options['auto_delete'];
136
    }
137
138
    /**
139
     * @param $noWait
140
     */
141
    public function setNoWait($noWait)
142
    {
143
        $this->options['no_wait'] = $noWait;
144
    }
145
146
    /**
147
     * @return bool
148
     */
149
    public function getNoWait()
150
    {
151
        return $this->options['no_wait'];
152
    }
153
154
    /**
155
     * @param array $arguments
156
     */
157
    public function setArguments(array $arguments)
158
    {
159
        $this->options['arguments'] = $arguments;
160
    }
161
162
    /**
163
     * @return string
164
     */
165
    public function getArguments()
166
    {
167
        return $this->options['arguments'];
168
    }
169
170
    /**
171
     * @param $ticket
172
     */
173
    public function setTicket($ticket)
174
    {
175
        $this->options['ticket'] = $ticket;
176
    }
177
178
    /**
179
     * @return string
180
     */
181
    public function getTicket()
182
    {
183
        return $this->options['ticket'];
184
    }
185
186
    /**
187
     * @param $consumerTag
188
     */
189
    public function setConsumerTag($consumerTag)
190
    {
191
        $this->options['consumer_tag'] = $consumerTag;
192
    }
193
194
    /**
195
     * @return string
196
     */
197
    public function getConsumerTag()
198
    {
199
        return $this->options['consumer_tag'];
200
    }
201
202
    /**
203
     * @param $noAck
204
     */
205
    public function setNoAck($noAck)
206
    {
207
        $this->options['no_ack'] = $noAck;
208
    }
209
210
    /**
211
     * @return bool
212
     */
213
    public function getNoAck()
214
    {
215
        return $this->options['no_ack'];
216
    }
217
218
    /**
219
     * @param $noLocal
220
     */
221
    public function setNoLocal($noLocal)
222
    {
223
        $this->options['no_local'] = $noLocal;
224
    }
225
226
    /**
227
     * @return bool
228
     */
229
    public function getNoLocal()
230
    {
231
        return $this->options['no_local'];
232
    }
233
234
    /**
235
     * @return array
236
     */
237
    public function getQueueDeclare()
238
    {
239
        return [
240
            $this->getQueue(),
241
            $this->getPassive(),
242
            $this->getDurable(),
243
            $this->getExclusive(),
244
            $this->getAutoDelete(),
245
            $this->getNoWait(),
246
            $this->getArguments(),
247
            $this->getTicket()
248
        ];
249
    }
250
251
    /**
252
     * @return array
253
     */
254
    public function getQueueConsume()
255
    {
256
        return [
257
            $this->getQueue(),
258
            $this->getConsumerTag(),
259
            $this->getNoLocal(),
260
            $this->getNoAck(),
261
            $this->getExclusive(),
262
            $this->getNoWait(),
263
            $this->getTicket(),
264
            $this->getArguments()
265
        ];
266
    }
267
268
    /**
269
     * @return array|false
270
     */
271
    public function getExchangeDeclare()
272
    {
273
        return false;
274
    }
275
276
    /**
277
     * @return string
278
     */
279
    public function getExchange()
280
    {
281
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type declared by the interface Cmobi\RabbitmqBundle\Que...gInterface::getExchange of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
282
    }
283
284
    /**
285
     * @return string
286
     */
287
    public function getType()
288
    {
289
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type declared by the interface Cmobi\RabbitmqBundle\Que...ueBagInterface::getType of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
290
    }
291
}