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

Vertex   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 9
c 1
b 0
f 1
dl 0
loc 65
ccs 12
cts 12
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getValue() 0 3 1
A __toString() 0 3 1
A getHash() 0 3 1
A equals() 0 3 1
1
<?php
2
3
namespace graphp\vertex;
4
5
/**
6
 * Class Vertex
7
 *
8
 * @package graphp\vertex
9
 */
10
class Vertex implements VertexInterface
11
{
12
    /**
13
     * The vertex unique hash
14
     *
15
     * @var string
16
     */
17
    private $hash;
18
19
    /**
20
     * The vertex value
21
     *
22
     * @var mixed
23
     */
24
    private $value;
25
    
26
    /**
27
     * Construct a new vertex
28
     *
29
     * @param mixed $value - value stored in vertex
30
     */
31 10
    public function __construct($value)
32
    {
33 10
        $this->value = $value;
34 10
        $this->hash = uniqid('', true);
35 10
    }
36
    
37
    /**
38
     * Check if two vertices are equal
39
     *
40
     * @param VertexInterface $other - other vertex to be compared
41
     */
42 2
    public function equals(VertexInterface $other): bool
43
    {
44 2
        return $this->hash == $other->getHash();
45
    }
46
    
47
    /**
48
     * Get the vertex hash
49
     *
50
     * @return string
51
     */
52 5
    public function getHash(): string
53
    {
54 5
        return $this->hash;
55
    }
56
    
57
    /**
58
     * Get the vertex value
59
     *
60
     * @return mixed
61
     */
62 1
    public function getValue()
63
    {
64 1
        return $this->value;
65
    }
66
    
67
    /**
68
     * Get the vertex string representation
69
     *
70
     * @return string
71
     */
72 1
    public function __toString(): string
73
    {
74 1
        return $this->value;
75
    }
76
}
77