Completed
Pull Request — master (#7)
by Volodymyr
02:27
created

AbstractCollectionArray::setAll()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.675

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 15
ccs 7
cts 10
cp 0.7
rs 8.8571
cc 5
eloc 8
nc 4
nop 1
crap 5.675
1
<?php
2
3
// Copyright (c) Lellys Informática. All rights reserved. See License.txt in the project root for license information.
4
namespace Collections;
5
6
/**
7
 * Provides the abstract base class for a strongly typed collection.
8
 */
9
abstract class AbstractCollectionArray extends AbstractConstCollectionArray implements
10
    CollectionInterface,
11
    IndexAccessInterface,
12
    ConstIndexAccessInterface,
13
    CollectionConvertableInterface,
14
    \Serializable,
15
    \JsonSerializable
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 1
    public function setAll($items)
21
    {
22 1
        if (!is_array($items) && !$items instanceof \Traversable) {
23
            throw new \InvalidArgumentException('Parameter must be an array or an instance of Traversable');
24
        }
25
26 1
        foreach ($items as $key => $item) {
27 1
            if (is_array($item)) {
28
                $item = new static($item);
29
            }
30 1
            $this->set($key, $item);
31 1
        }
32
33 1
        return $this;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 1
    public function clear()
40
    {
41 1
        $this->container = [];
42
43 1
        return $this;
44
    }
45
}
46