Completed
Push — master ( 44b88c...ea2c59 )
by Pablo
03:18
created

ObjectCollection::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace PhpValueObjects\Collection;
4
5
use PhpValueObjects\Collection\Exception\InvalidCollectionObjectException;
6
7
abstract class ObjectCollection
8
{
9
    /**
10
     * @var array
11
     */
12
    private $objects;
13
14
    /**
15
     * ObjectCollection constructor.
16
     * @param array $objects
17
     * @throws InvalidCollectionObjectException
18
     */
19
    public function __construct(array $objects)
20
    {
21
        foreach ($objects as $object) {
22
            if (false === is_a($object, $this->setClassName())) {
23
                throw new InvalidCollectionObjectException($object, $this->setClassName());
24
            }
25
        }
26
        $this->objects = $objects;
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    abstract protected function setClassName();
33
34
    /**
35
     * @return array
36
     */
37
    public function getCollection()
38
    {
39
        return $this->objects;
40
    }
41
42
}
43