Test Failed
Push — master ( 492ea4...9c8472 )
by Bingo
04:47
created

UndirectedEdgeContainer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A edgeCount() 0 3 1
A __construct() 0 3 1
A addEdge() 0 3 1
A removeEdge() 0 6 3
A getEdges() 0 3 1
1
<?php
2
3
namespace Graphp\Graph\Specifics;
4
5
use Graphp\Edge\EdgeInterface;
6
use Graphp\Edge\EdgeSetFactoryInterface;
7
use Graphp\Edge\EdgeContainerInterface;
8
use Graphp\Edge\EdgeSet;
9
use Graphp\Vertex\VertexInterface;
10
11
/**
12
 * Class UndirectedEdgeContainer
13
 *
14
 * @package Graphp\Graph\Specifics
15
 */
16
final class UndirectedEdgeContainer implements EdgeContainerInterface
17
{
18
    /**
19
     * Container vertex edges
20
     *
21
     * @var array
22
     */
23
    private $vertexEdges = [];
24
    
25
    /**
26
     * Construct undirected edge container
27
     *
28
     * @param EdgeSetFactoryInterface $edgeSetFactory - the edge set factory
29
     * @param VertexInterface $vertex - the vertex
30
     */
31 6
    public function __construct(EdgeSetFactoryInterface $edgeSetFactory, VertexInterface $vertex)
32
    {
33 6
        $this->vertexEdges = $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 $vertexEdges.

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...
34 6
    }
35
    
36
    /**
37
     * Add an edge to the container
38
     *
39
     * @param EdgeInterface $edge - the edge to be added
40
     */
41 5
    public function addEdge(EdgeInterface $edge): void
42
    {
43 5
        $this->vertexEdges[] = $edge;
44 5
    }
45
    
46
    /**
47
     * Remove the edge from the container
48
     *
49
     * @param EdgeInterface $edge - the edge to be removed
50
     */
51 1
    public function removeEdge(EdgeInterface $edge): void
52
    {
53 1
        foreach ($this->vertexEdges as $key => $e) {
54 1
            if ($edge->equals($e)) {
55 1
                unset($this->vertexEdges[$key]);
56 1
                break;
57
            }
58
        }
59 1
    }
60
    
61
    /**
62
     * Get all container edges
63
     *
64
     * @return EdgeSet
65
     */
66 6
    public function getEdges(): EdgeSet
67
    {
68 6
        return $this->vertexEdges;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->vertexEdges returns the type array which is incompatible with the type-hinted return Graphp\Edge\EdgeSet.
Loading history...
69
    }
70
71
    /**
72
     * Get the number of edges
73
     *
74
     * @return int
75
     */
76
    public function edgeCount(): int
77
    {
78
        return count($this->vertexEdges);
79
    }
80
}
81