CollectionMethods::containsAll()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 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