Issues (34)

src/Graph/Specifics/DirectedEdgeContainer.php (4 issues)

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 27
    public function __construct(EdgeSetFactoryInterface $edgeSetFactory, VertexInterface $vertex)
39
    {
40 27
        $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 27
        $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 27
    }
43
    
44
    /**
45
     * Get container outgoing edges
46
     *
47
     * @return EdgeSet
48
     */
49 24
    public function getOutgoing(): EdgeSet
50
    {
51 24
        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 9
    public function getIncoming(): EdgeSet
60
    {
61 9
        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 23
    public function addOutgoingEdge(EdgeInterface $edge): void
70
    {
71 23
        $this->outgoing[] = $edge;
72 23
    }
73
    
74
    /**
75
     * Add the incoming edge
76
     *
77
     * @param EdgeInterface $edge - the edge to be added
78
     */
79 23
    public function addIncomingEdge(EdgeInterface $edge): void
80
    {
81 23
        $this->incoming[] = $edge;
82 23
    }
83
    
84
    /**
85
     * Remove outgoing edge
86
     *
87
     * @param EdgeInterface $edge - the edge to be removed
88
     */
89 4
    public function removeOutgoingEdge(EdgeInterface $edge): void
90
    {
91 4
        foreach ($this->outgoing as $key => $e) {
92 4
            if ($edge->equals($e)) {
93 4
                unset($this->outgoing[$key]);
94 4
                break;
95
            }
96
        }
97 4
    }
98
    
99
    /**
100
     * Remove incoming edge
101
     *
102
     * @param EdgeInterface $edge - the edge to be removed
103
     */
104 4
    public function removeIncomingEdge(EdgeInterface $edge): void
105
    {
106 4
        foreach ($this->incoming as $key => $e) {
107 4
            if ($edge->equals($e)) {
108 4
                unset($this->incoming[$key]);
109 4
                break;
110
            }
111
        }
112 4
    }
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