Vertex::addNeighbour()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
/**
3
 * @copyright 2018 Aleksander Stelmaczonek <[email protected]>
4
 * @license   MIT License, see license file distributed with this source code
5
 */
6
7
namespace Koriit\PHPDeps\Graph;
8
9
class Vertex
10
{
11
    /** @var mixed Held value */
12
    private $value;
13
14
    /** @var Vertex[] */
15
    private $neighbours;
16
17
    /** @var int The index in the graph */
18
    private $index = null;
19
20
    public function __construct($value, array $neighbours = [])
21
    {
22
        $this->value = $value;
23
        $this->neighbours = $neighbours;
24
    }
25
26
    /**
27
     * @return mixed
28
     */
29
    public function getValue()
30
    {
31
        return $this->value;
32
    }
33
34
    public function getNeighbours()
35
    {
36
        return $this->neighbours;
37
    }
38
39
    /**
40
     * @param Vertex $neighbour
41
     */
42
    public function addNeighbour(Vertex $neighbour)
43
    {
44
        if (!\in_array($neighbour, $this->neighbours)) {
45
            $this->neighbours[] = $neighbour;
46
        }
47
    }
48
49
    public function getIndex()
50
    {
51
        return $this->index;
52
    }
53
54
    public function setIndex($index)
55
    {
56
        $this->index = $index;
57
    }
58
}
59