QueueChannel   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 12.5 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 3 Features 0
Metric Value
wmc 7
c 4
b 3
f 0
lcom 1
cbo 1
dl 7
loc 56
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMessageCount() 0 4 1
A getCapacity() 0 4 1
A setCapacity() 0 4 1
A doSend() 7 8 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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