Passed
Push — master ( e5acb2...2b13b1 )
by Evgeny
07:45
created

Collection::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 12
ccs 0
cts 9
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
4
 *
5
 * Licensed under The MIT License
6
 * Redistributions of files must retain the above copyright notice.
7
 *
8
 * @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
9
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10
 */
11
12
namespace CakeDC\Api;
13
14
use ArrayIterator;
15
use Cake\Core\InstanceConfigTrait;
16
use Cake\Core\ObjectRegistry;
17
use IteratorAggregate;
18
19
abstract class Collection extends ObjectRegistry implements IteratorAggregate
20
{
21
    use InstanceConfigTrait;
22
23
    /**
24
     * Config array.
25
     *
26
     * @var array
27
     */
28
    protected $_defaultConfig = [];
29
30
    /**
31
     * Constructor
32
     *
33
     * @param array $config Configuration
34
     */
35
    public function __construct(array $config = [])
36
    {
37
        $this->setConfig($config);
38
39
        foreach ($config as $key => $value) {
40
            if (is_int($key)) {
41
                $this->load($value);
42
                continue;
43
            }
44
            $this->load($key, $value);
45
        }
46
    }
47
48
    /**
49
     * Returns true if a collection is empty.
50
     *
51
     * @return bool
52
     */
53
    public function isEmpty()
54
    {
55
        return empty($this->_loaded);
56
    }
57
58
    /**
59
     * Returns iterator.
60
     *
61
     * @return \ArrayIterator
62
     */
63
    public function getIterator()
64
    {
65
        return new ArrayIterator($this->_loaded);
66
    }
67
}
68