Set::remove()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the bisarca/graph package.
5
 *
6
 * (c) Emanuele Minotto <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bisarca\Graph\Edge;
13
14
use Bisarca\Graph\AbstractSet;
15
16
/**
17
 * Set of edges.
18
 */
19 View Code Duplication
class Set extends AbstractSet
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
    /**
22
     * Sets the optional contained edges.
23
     *
24
     * @param EdgeInterface[] $edges
25
     */
26
    public function __construct(EdgeInterface ...$edges)
27
    {
28
        $this->data = $edges;
29
    }
30
31
    /**
32
     * Sets the contained edges.
33
     *
34
     * @param EdgeInterface[] $edges
35
     */
36
    public function set(EdgeInterface ...$edges)
37
    {
38
        $this->data = $edges;
39
    }
40
41
    /**
42
     * Adds some edges.
43
     *
44
     * @param EdgeInterface[] $edges
45
     */
46
    public function add(EdgeInterface ...$edges)
47
    {
48
        $this->data = array_merge($this->data, $edges);
49
    }
50
51
    /**
52
     * Checks if all the edges are contained.
53
     *
54
     * @param EdgeInterface[] $edges
55
     *
56
     * @return bool
57
     */
58
    public function has(EdgeInterface ...$edges): bool
59
    {
60
        $intersection = array_uintersect(
61
            $this->data,
62
            $edges,
63
            function (EdgeInterface $a, EdgeInterface $b) {
64
                return $a !== $b;
65
            }
66
        );
67
68
        return count($intersection) === count($edges);
69
    }
70
71
    /**
72
     * Removes some edges.
73
     *
74
     * @param EdgeInterface[] $edges
75
     */
76
    public function remove(EdgeInterface ...$edges)
77
    {
78
        $this->data = array_udiff(
79
            $this->data,
80
            $edges,
81
            function (EdgeInterface $a, EdgeInterface $b) {
82
                return $a !== $b;
83
            }
84
        );
85
    }
86
}
87