Completed
Branch master (d31b6a)
by Bingo
05:22 queued 01:30
created

DirectedEdgeContainer   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 12
eloc 18
c 1
b 0
f 1
dl 0
loc 106
ccs 26
cts 28
cp 0.9286
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getOutgoing() 0 3 1
A addIncomingEdge() 0 3 1
A removeIncomingEdge() 0 6 3
A __construct() 0 4 1
A removeOutgoingEdge() 0 6 3
A edgeCount() 0 3 1
A getIncoming() 0 3 1
A addOutgoingEdge() 0 3 1
1
<?php
2
3
namespace graphp\graph\specifics;
4
5
use graphp\edge\EdgeInterface;
6
use graphp\edge\EdgeContainerInterface;
7
use graphp\edge\EdgeSetFactoryInterface;
8
use graphp\edge\EdgeSet;
9
use graphp\vertex\VertexInterface;
10
11
/**
12
 * Class DirectedEdgeContainer
13
 *
14
 * @package graphp\graph\specifics
15
 */
16
class DirectedEdgeContainer implements EdgeContainerInterface
17
{
18
    /**
19
     * Outgoing vertex edges
20
     *
21
     * @var array
22
     */
23
    private $outgoing;
24
    
25
    /**
26
     * Incoming vertex edges
27
     *
28
     * @var array
29
     */
30
    private $incoming;
31
    
32
    /**
33
     * Construct directed edge container
34
     *
35
     * @param EdgeSetFactoryInterface $edgeSetFactory - the edge set factory
36
     * @param VertexInterface $vertex - the vertex
37
     */
38 4
    public function __construct(EdgeSetFactoryInterface $edgeSetFactory, VertexInterface $vertex)
39
    {
40 4
        $this->outgoing = $edgeSetFactory->createEdgeSet($vertex);
0 ignored issues
show
Documentation Bug introduced by
It seems like $edgeSetFactory->createEdgeSet($vertex) of type graphp\edge\EdgeSet is incompatible with the declared type array of property $outgoing.

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...
41 4
        $this->incoming = $edgeSetFactory->createEdgeSet($vertex);
0 ignored issues
show
Documentation Bug introduced by
It seems like $edgeSetFactory->createEdgeSet($vertex) of type graphp\edge\EdgeSet is incompatible with the declared type array of property $incoming.

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...
42 4
    }
43
    
44
    /**
45
     * Get container outgoing edges
46
     *
47
     * @return EdgeSet
48
     */
49 2
    public function getOutgoing(): EdgeSet
50
    {
51 2
        return $this->outgoing;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->outgoing returns the type array which is incompatible with the type-hinted return graphp\edge\EdgeSet.
Loading history...
52
    }
53
    
54
    /**
55
     * Get container incoming edges
56
     *
57
     * @return EdgeSet
58
     */
59 2
    public function getIncoming(): EdgeSet
60
    {
61 2
        return $this->incoming;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->incoming returns the type array which is incompatible with the type-hinted return graphp\edge\EdgeSet.
Loading history...
62
    }
63
    
64
    /**
65
     * Add the outgoing edge
66
     *
67
     * @param EdgeInterface $edge - the edge to be added
68
     */
69 2
    public function addOutgoingEdge(EdgeInterface $edge): void
70
    {
71 2
        $this->outgoing[] = $edge;
72 2
    }
73
    
74
    /**
75
     * Add the incoming edge
76
     *
77
     * @param EdgeInterface $edge - the edge to be added
78
     */
79 2
    public function addIncomingEdge(EdgeInterface $edge): void
80
    {
81 2
        $this->incoming[] = $edge;
82 2
    }
83
    
84
    /**
85
     * Remove outgoing edge
86
     *
87
     * @param EdgeInterface $edge - the edge to be removed
88
     */
89 1
    public function removeOutgoingEdge(EdgeInterface $edge): void
90
    {
91 1
        foreach ($this->outgoing as $key => $e) {
92 1
            if ($edge->equals($e)) {
93 1
                unset($this->outgoing[$key]);
94 1
                break;
95
            }
96
        }
97 1
    }
98
    
99
    /**
100
     * Remove incoming edge
101
     *
102
     * @param EdgeInterface $edge - the edge to be removed
103
     */
104 1
    public function removeIncomingEdge(EdgeInterface $edge): void
105
    {
106 1
        foreach ($this->incoming as $key => $e) {
107 1
            if ($edge->equals($e)) {
108 1
                unset($this->incoming[$key]);
109 1
                break;
110
            }
111
        }
112 1
    }
113
114
    /**
115
     * Get the number of edges
116
     *
117
     * @return int
118
     */
119
    public function edgeCount(): int
120
    {
121
        return count($this->outgoing) + count($this->incoming);
122
    }
123
}
124