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.

DoctrineEventsRecorder::onFlush()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
rs 10
ccs 7
cts 7
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\EventAware;
10
use Dsantang\DomainEventsDoctrine\Aggregator;
11
12
use function array_filter;
13
use function array_merge;
14
15
/**
16
 * Doctrine's listener in charge of staging the domain events before the flush operation is completed.
17
 */
18
final class DoctrineEventsRecorder
19
{
20
    private Aggregator $eventAggregator;
21
22 2
    public function __construct(Aggregator $eventAggregator)
23
    {
24 2
        $this->eventAggregator = $eventAggregator;
25 2
    }
26
27 2
    public function onFlush(OnFlushEventArgs $eventArgs): void
28
    {
29 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

29
        $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...
30 2
                                ->getUnitOfWork();
31
32 2
        $events = [];
33
34 2
        foreach (self::getEventAwareEntities($unitOfWork) as $entity) {
35 1
            $events = array_merge($events, $entity->expelRecordedEvents());
36
        }
37
38 2
        $this->eventAggregator->aggregate(...$events);
39 2
    }
40
41
    /**
42
     * @return EventAware[]
43
     */
44 2
    private static function getEventAwareEntities(UnitOfWork $unitOfWork): array
45
    {
46 2
        $entities = array_merge(
47 2
            $unitOfWork->getScheduledEntityInsertions(),
48 2
            $unitOfWork->getScheduledEntityUpdates(),
49 2
            $unitOfWork->getScheduledEntityDeletions()
50
        );
51
52
        return array_filter($entities, static fn ($entity): bool => $entity instanceof EventAware);
53 2
    }
54
}
55