CollectionMethods   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 0
loc 41
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
add() 0 1 ?
contains() 0 1 ?
A addAll() 0 8 3
A containsAll() 0 9 3
A containsAny() 0 9 3
1
<?php
2
namespace GenericCollections\Traits;
3
4
/**
5
 * This methods apply to BaseCollectionInterface and
6
 * its shared between all the different AbstractCollections like
7
 * AbstractCollection and AbstractMap
8
 *
9
 * This methods are declared to avoid warnings
10
 *
11
 * @package GenericCollections\Traits
12
 */
13
trait CollectionMethods
14
{
15
    /**
16
     * @inheritdoc \GenericCollections\Interfaces\BaseCollectionInterface::add
17
     */
18
    abstract public function add($element);
19
20
    /**
21
     * @inheritdoc \GenericCollections\Interfaces\BaseCollectionInterface::contains
22
     */
23
    abstract public function contains($element);
24
25 112
    public function addAll(array $elements)
26
    {
27 112
        $added = false;
28 112
        foreach ($elements as $element) {
29 58
            $added = $this->add($element) || $added;
30
        }
31 112
        return $added;
32
    }
33
34 1
    public function containsAll(array $elements)
35
    {
36 1
        foreach ($elements as $element) {
37 1
            if (! $this->contains($element)) {
38 1
                return false;
39
            }
40
        }
41 1
        return true;
42
    }
43
44 1
    public function containsAny(array $elements)
45
    {
46 1
        foreach ($elements as $element) {
47 1
            if ($this->contains($element)) {
48 1
                return true;
49
            }
50
        }
51 1
        return false;
52
    }
53
}
54