MessagePersistSubscriber::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 0
c 0
b 0
f 0
dl 0
loc 2
rs 10
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Doctrine;
4
5
use App\Entity\Message;
6
use App\Event\MessageCreatedEvent;
7
use Doctrine\Common\EventSubscriber;
8
use Doctrine\ORM\Event\LifecycleEventArgs;
9
use Doctrine\ORM\Events;
10
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
11
12
/**
13
 * This listener listens for new messages being created and
14
 * dispatches an event into the EventDispatcher
15
 */
16
class MessagePersistSubscriber implements EventSubscriber {
17
18
    public function __construct(private EventDispatcherInterface $dispatcher)
19
    {
20
    }
21 25
22 25
    public function postPersist(LifecycleEventArgs $eventArgs) {
23 25
        $entity = $eventArgs->getEntity();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\Event\LifecycleEventArgs::getEntity() has been deprecated: 2.13. Use {@see getObject} instead. ( Ignorable by Annotation )

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

23
        $entity = /** @scrutinizer ignore-deprecated */ $eventArgs->getEntity();

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...
24
25 21
        if($entity instanceof Message) {
26 21
            $this->dispatcher->dispatch(new MessageCreatedEvent($entity));
27
        }
28 21
    }
29 1
30
    /**
31 21
     * @inheritDoc
32
     */
33
    public function getSubscribedEvents(): array {
34
        return [
35
            Events::postPersist
36 25
        ];
37
    }
38
}