GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 186bd8...f8fd37 )
by Davide
49s
created

OrderedDoctrineEventsRecorder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dsantang\DomainEventsDoctrine\EventsRecorder;
6
7
use Doctrine\ORM\Event\OnFlushEventArgs;
8
use Doctrine\ORM\UnitOfWork;
9
use Dsantang\DomainEvents\Counter;
10
use Dsantang\DomainEvents\EventAware;
11
use Dsantang\DomainEventsDoctrine\Aggregator;
12
use function array_filter;
13
use function array_merge;
14
use function ksort;
15
16
final class OrderedDoctrineEventsRecorder
17
{
18
    /** @var Aggregator */
19
    private $eventsAggregator;
20
21 2
    public function __construct(Aggregator $eventAggregator)
22
    {
23 2
        $this->eventsAggregator = $eventAggregator;
24 2
    }
25
26 2
    public function onFlush(OnFlushEventArgs $eventArgs) : void
27
    {
28 2
        $unitOfWork = $eventArgs->getEntityManager()
29 2
                                ->getUnitOfWork();
30
31 2
        $events = [];
32
33 2
        foreach (self::getEventAwareEntities($unitOfWork) as $entity) {
34 1
            $events += $entity->expelRecordedEvents();
35
        }
36
37 2
        ksort($events);
38
39 2
        Counter::reset();
40 2
        $this->eventsAggregator->aggregate(...$events);
41 2
    }
42
43
    /**
44
     * @return EventAware[]
45
     */
46 2
    private static function getEventAwareEntities(UnitOfWork $unitOfWork) : array
47
    {
48 2
        $entities = array_merge(
49 2
            $unitOfWork->getScheduledEntityInsertions(),
50 2
            $unitOfWork->getScheduledEntityUpdates(),
51 2
            $unitOfWork->getScheduledEntityDeletions()
52
        );
53
54
        return array_filter($entities, static function ($entity) {
55 2
            return $entity instanceof EventAware;
56 2
        });
57
    }
58
}
59