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   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 40
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getEventAwareEntities() 0 10 1
A onFlush() 0 15 2
A __construct() 0 3 1
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