CollectionTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A replace() 0 5 1
A addAll() 0 9 3
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