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

VertexSet   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A contains() 0 3 1
A remove() 0 4 2
1
<?php
2
3
namespace Graphp\Vertex;
4
5
use ArrayObject;
6
7
/**
8
 * Class VertexSet
9
 *
10
 * @package Graphp\Vertex
11
 */
12
class VertexSet extends ArrayObject
13
{
14
    /**
15
     * Construct a set of vertices
16
     *
17
     * @param array $input - array of vertices
18
     */
19 32
    public function __construct(array $input = [])
20
    {
21 32
        parent::__construct($input, ArrayObject::ARRAY_AS_PROPS);
22 32
    }
23
    
24
    /**
25
     * Check if the set contains the vertex
26
     *
27
     * @param VertexInterface $vertex - niddle
28
     */
29 30
    public function contains(VertexInterface $vertex): bool
30
    {
31 30
        return in_array($vertex, $this->getArrayCopy());
32
    }
33
    
34
    /**
35
     * Remove the vertex from the set
36
     *
37
     * @param VertexInterface $vertex - niddle
38
     */
39 1
    public function remove(VertexInterface $vertex): void
40
    {
41 1
        if (($id = array_search($vertex, $this->getArrayCopy())) !== false) {
42 1
            unset($this[$id]);
43
        }
44 1
    }
45
}
46