Completed
Push — master ( 74f550...2d3688 )
by Peter
01:46
created

EventPuller   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 42
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pull() 0 15 2
A pullFromEntities() 0 13 4
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Bundle\DomainEvent\Service;
12
13
use Doctrine\Common\Persistence\Proxy;
14
use Doctrine\ORM\UnitOfWork;
15
use GpsLab\Domain\Event\Aggregator\AggregateEvents;
16
use GpsLab\Domain\Event\Event;
17
18
class EventPuller
19
{
20
    /**
21
     * @param UnitOfWork $uow
22
     *
23
     * @return Event[]
24
     */
25 15
    public function pull(UnitOfWork $uow)
26
    {
27 15
        $events = [];
28
29 15
        $events = array_merge($events, $this->pullFromEntities($uow->getScheduledEntityDeletions()));
30 15
        $events = array_merge($events, $this->pullFromEntities($uow->getScheduledEntityInsertions()));
31 15
        $events = array_merge($events, $this->pullFromEntities($uow->getScheduledEntityUpdates()));
32
33
        // other entities
34 15
        foreach ($uow->getIdentityMap() as $entities) {
35 8
            $events = array_merge($events, $this->pullFromEntities($entities));
36
        }
37
38 15
        return $events;
39
    }
40
41
    /**
42
     * @param array $entities
43
     *
44
     * @return Event[]
45
     */
46 15
    private function pullFromEntities(array $entities)
47
    {
48 15
        $events = [];
49 15
        foreach ($entities as $entity) {
50
            // ignore Doctrine proxy classes
51
            // proxy class can't have a domain events
52 14
            if (!($entity instanceof Proxy) && $entity instanceof AggregateEvents) {
53 14
                $events = array_merge($events, $entity->pullEvents());
54
            }
55
        }
56
57 15
        return $events;
58
    }
59
}
60