CollectionTrait::addAll()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Bdf\Collection;
4
5
/**
6
 * Base implementation of CollectionInterface methods
7
 */
8
trait CollectionTrait
9
{
10
    /**
11
     * @see CollectionInterface::add()
12
     */
13
    abstract public function add($element): bool;
14
15
    /**
16
     * @see CollectionInterface::addAll()
17
     */
18 6
    public function addAll(iterable $elements): bool
19
    {
20 6
        $b = true;
21
22 6
        foreach ($elements as $item) {
23 6
            $b = $this->add($item) && $b;
24
        }
25
26 6
        return $b;
27
    }
28
29
    /**
30
     * @see CollectionInterface::clear()
31
     */
32
    abstract public function clear(): void;
33
34
    /**
35
     * @see CollectionInterface::replace()
36
     */
37 3
    public function replace(iterable $elements): bool
38
    {
39 3
        $this->clear();
40
41 3
        return $this->addAll($elements);
42
    }
43
}
44