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

Vertex::getHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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