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.

OrderedDoctrineEventsRecorder::onFlush()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 15
rs 10
ccs 9
cts 9
cp 1
cc 2
nc 2
nop 1
crap 2
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
13
use function array_filter;
14
use function array_merge;
15
use function ksort;
16
17
final class OrderedDoctrineEventsRecorder
18
{
19
    private Aggregator $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()
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\Event\OnFlu...rgs::getEntityManager() has been deprecated: 2.13. Use {@see getObjectManager} instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

28
        $unitOfWork = /** @scrutinizer ignore-deprecated */ $eventArgs->getEntityManager()

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
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 fn ($entity): bool => $entity instanceof EventAware);
55 2
    }
56
}
57