EventPuller::pull()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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 not initialized proxy classes
51
            // proxy class can't have a domain events
52 14
            if ((!($entity instanceof Proxy) || $entity->__isInitialized()) && $entity instanceof AggregateEvents) {
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...
53 14
                $events = array_merge($events, $entity->pullEvents());
54
            }
55
        }
56
57 15
        return $events;
58
    }
59
}
60