SetManager::remove()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
crap 3
1
<?php
2
3
namespace Accessible\MethodManager;
4
5
class SetManager extends CollectionManager
6
{
7
    /**
8
     * Adds an element to the set if it is not already present.
9
     *
10
     * @param array|Traversable $set
11
     * @param array $args
12
     */
13 4
    public static function add(&$set, $args)
14
    {
15 4
        self::assertArgsNumber(1, $args);
16
17 4
        $value = $args[0];
18
19 4
        foreach ($set as $item) {
20 4
            if ($item === $value) {
21 1
                return;
22
            }
23 4
        }
24
25 4
        $set[] = $value;
26 4
    }
27
28
    /**
29
     * Removes an element from the set.
30
     *
31
     * @param  array|Traversable $set
32
     * @param  array $args
33
     */
34 4
    public static function remove(&$set, $args)
35
    {
36 4
        self::assertArgsNumber(1, $args);
37
38 4
        foreach ($set as $key => $value) {
39 4
            if ($value === $args[0]) {
40 4
                unset($set[$key]);
41 4
                return;
42
            }
43 3
        }
44 1
    }
45
}
46