CollectionTrait::getCollections()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace AssetManager\Core\Resolver;
4
5
use AssetManager\Core\Exception\InvalidArgumentException;
6
use Zend\Stdlib\ArrayUtils;
7
8
trait CollectionTrait
9
{
10
    /**
11
     * @var array the collections
12
     */
13
    protected $collections = array();
14
15
    /**
16
     * Set (overwrite) collections
17
     *
18
     * Collections should be arrays or Traversable objects with name => path pairs
19
     *
20
     * @param  array|\Traversable                  $collections
21
     *
22
     * @throws InvalidArgumentException
23
     */
24
    public function setCollections($collections)
25
    {
26
        if (!is_array($collections) && !$collections instanceof \Traversable) {
27
            throw new InvalidArgumentException(sprintf(
28
                '%s: expects an array or Traversable, received "%s"',
29
                __METHOD__,
30
                (is_object($collections) ? get_class($collections) : gettype($collections))
31
            ));
32
        }
33
34
        if ($collections instanceof \Traversable) {
35
            $collections = ArrayUtils::iteratorToArray($collections);
36
        }
37
38
        $this->collections = $collections;
39
    }
40
41
    /**
42
     * Retrieve the collections
43
     *
44
     * @return array
45
     */
46
    public function getCollections()
47
    {
48
        return $this->collections;
49
    }
50
}
51