QueueChannel::doSend()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 7
Ratio 87.5 %

Importance

Changes 4
Bugs 3 Features 0
Metric Value
c 4
b 3
f 0
dl 7
loc 8
rs 9.4285
cc 3
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace PEIP\Channel;
4
5
/*
6
 * This file is part of the PEIP package.
7
 * (c) 2009-2016 Timo Michna <timomichna/yahoo.de>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
use SplQueue;
14
15
/**
16
 * QueueChannel.
17
 *
18
 * @author Timo Michna <timomichna/yahoo.de>
19
 * @extends \PEIP\ABS\Channel\PollableChannel
20
 * @implements \PEIP\INF\Channel\PollableChannel, \PEIP\INF\Channel\Channel, \PEIP\INF\Event\Connectable
21
 */
22
class QueueChannel extends \PEIP\ABS\Channel\PollableChannel
23
{
24
    protected $capacity,
25
        $queue;
26
27
    /**
28
     * @param $capacity
29
     *
30
     * @return
31
     */
32
    public function __construct($capacity = -1)
33
    {
34
        $this->setCapacity((int) $capacity);
35
        $this->queue = new SplQueue();
36
    }
37
38
    /**
39
     * @return
40
     */
41
    public function getMessageCount()
42
    {
43
        return count($this->messages);
44
    }
45
46
    /**
47
     * @return
48
     */
49
    public function getCapacity()
50
    {
51
        return $this->capacity;
52
    }
53
54
    /**
55
     * @param $capacity
56
     *
57
     * @return
58
     */
59
    public function setCapacity($capacity)
60
    {
61
        $this->capacity = $capacity;
62
    }
63
64
    /**
65
     * @param $message
66
     *
67
     * @return
68
     */
69 View Code Duplication
    protected function doSend(\PEIP\INF\Message\Message $message)
0 ignored issues
show
Duplication introduced by
This method 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...
70
    {
71
        if ($this->capacity < 1 || $this->getMessageCount() <= $this->getCapacity()) {
72
            $this->queue->enqueque($message);
73
        } else {
74
            throw new \Exception('Not implemented yet.');
75
        }
76
    }
77
}
78