EventPipe   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 32.56 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 3 Features 0
Metric Value
wmc 5
c 3
b 3
f 0
lcom 1
cbo 2
dl 14
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A doListen() 7 7 2
A doUnlisten() 7 7 2
A doGetConnected() 0 4 1

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\ABS\Pipe;
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
/*
14
 * PEIP\ABS\Pipe\EventPipe
15
 * Abstract base class for all event handling Pipes.
16
 *
17
 * @author Timo Michna <timomichna/yahoo.de>
18
 * @package PEIP
19
 * @subpackage pipe
20
 * @extends \PEIP\Pipe\Pipe
21
 * @abstract
22
 * @implements \PEIP\INF\Event\Connectable, \PEIP\INF\Channel\SubscribableChannel, \PEIP\INF\Channel\Channel, \PEIP\INF\Handler\Handler, \PEIP\INF\Message\MessageBuilder
23
 */
24
25
use PEIP\Pipe\Pipe;
26
27
abstract class EventPipe extends \PEIP\Pipe\Pipe
28
{
29
    protected $connections = [];
30
31
    /**
32
     * Connects the event-pipe to a given \PEIP\INF\Event\Connectable instance by listening
33
     * to a given event on the connectable.
34
     *
35
     * @param string                      $eventName   name of the event to listen to
36
     * @param \PEIP\INF\Event\Connectable $connectable instance of \PEIP\INF\Event\Connectable to listen to
37
     */
38 View Code Duplication
    protected function doListen($eventName, \PEIP\INF\Event\Connectable $connectable)
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...
39
    {
40
        if (!$connectable->hasListener($eventName, $this)) {
0 ignored issues
show
Bug introduced by
The method hasListener() does not exist on PEIP\INF\Event\Connectable. Did you maybe mean hasListeners()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
41
            $connectable->connect($eventName, $this);
42
            $this->connections[spl_object_hash($connectable)] = $connectable;
43
        }
44
    }
45
46
    /**
47
     * Disonnects the event-pipe from listening to a given event on a \PEIP\INF\Event\Connectable instance.
48
     *
49
     * @param string                      $eventName   name of the event to unlisten
50
     * @param \PEIP\INF\Event\Connectable $connectable instance of \PEIP\INF\Event\Connectable to unlisten to
51
     */
52 View Code Duplication
    protected function doUnlisten($eventName, \PEIP\INF\Event\Connectable $connectable)
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...
53
    {
54
        if (!$connectable->hasListener($eventName, $this)) {
0 ignored issues
show
Bug introduced by
The method hasListener() does not exist on PEIP\INF\Event\Connectable. Did you maybe mean hasListeners()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
55
            $connectable->disconnect($eventName, $this);
56
            unset($this->connections[spl_object_hash($connectable)]);
57
        }
58
    }
59
60
    /**
61
     * Returns the instances of \PEIP\INF\Event\Connectable the event-pipe is litening to.
62
     *
63
     * @return array array of \PEIP\INF\Event\Connectable instances
64
     */
65
    public function doGetConnected()
66
    {
67
        return array_values($this->connections);
68
    }
69
}
70