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

EdgeSet   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 5
c 1
b 0
f 1
dl 0
loc 31
ccs 8
cts 8
cp 1
rs 10

3 Methods

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