Completed
Pull Request — master (#21)
by Pavel
21:56
created

CollectionCrudEvent::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 7
cp 0.8571
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
crap 3.0261
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Event;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
8
class CollectionCrudEvent extends CrudEvent
9
{
10
    /** @var Collection */
11
    private $entities = [];
12
13
    /**
14
     * CollectionCrudEvent constructor.
15
     *
16
     * @param object|object[]|Collection $entities
17
     */
18 38
    public function __construct($entities)
19
    {
20 38
        if ($entities instanceof Collection) {
21 6
            $this->entities = $entities;
22 32
        } elseif (is_array($entities)) {
23 32
            $this->entities = new ArrayCollection($entities);
24
        } else {
25
            $this->entities = new ArrayCollection([$entities]);
26
        }
27 38
    }
28
29
    /**
30
     * @return Collection
31
     */
32
    public function getEntities()
33
    {
34
        return $this->entities;
35
    }
36
}
37