Completed
Pull Request — master (#12)
by Peter
01:21
created

EventPuller::pullFromEntities()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 9
cts 9
cp 1
rs 8.6506
c 0
b 0
f 0
cc 7
nc 4
nop 1
crap 7
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 as CommonProxy;
14
use Doctrine\Persistence\Proxy;
15
use Doctrine\ORM\UnitOfWork;
16
use GpsLab\Domain\Event\Aggregator\AggregateEvents;
17
use GpsLab\Domain\Event\Event;
18
19
class EventPuller
20
{
21
    /**
22
     * @param UnitOfWork $uow
23
     *
24
     * @return Event[]
25
     */
26 15
    public function pull(UnitOfWork $uow)
27
    {
28 15
        $events = [];
29
30 15
        $events = array_merge($events, $this->pullFromEntities($uow->getScheduledEntityDeletions()));
31 15
        $events = array_merge($events, $this->pullFromEntities($uow->getScheduledEntityInsertions()));
32 15
        $events = array_merge($events, $this->pullFromEntities($uow->getScheduledEntityUpdates()));
33
34
        // other entities
35 15
        foreach ($uow->getIdentityMap() as $entities) {
36 8
            $events = array_merge($events, $this->pullFromEntities($entities));
37
        }
38
39 15
        return $events;
40
    }
41
42
    /**
43
     * @param array $entities
44
     *
45
     * @return Event[]
46
     */
47 15
    private function pullFromEntities(array $entities)
48
    {
49 15
        $events = [];
50
51 15
        foreach ($entities as $entity) {
52
            // ignore Doctrine not initialized proxy classes
53
            // proxy class can't have a domain events
54
            if (
55 14
                ($entity instanceof Proxy && !$entity->__isInitialized()) ||
56 14
                ($entity instanceof CommonProxy && !$entity->__isInitialized())
0 ignored issues
show
Bug introduced by
The class Doctrine\Common\Persistence\Proxy does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
57
            ) {
58 14
                continue;
59
            }
60
61 14
            if ($entity instanceof AggregateEvents) {
62 14
                $events = array_merge($events, $entity->pullEvents());
63
            }
64
        }
65
66 15
        return $events;
67
    }
68
}
69