MessagePersistSubscriber   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 20
rs 10
ccs 8
cts 8
cp 1
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A postPersist() 0 5 2
A __construct() 0 2 1
A getSubscribedEvents() 0 3 1
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
}