Passed
Pull Request — master (#216)
by Charly
03:36
created

CommentEventSubscriber::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Fixtures\Event;
4
5
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
6
use Doctrine\ORM\Event\LifecycleEventArgs;
7
use Doctrine\ORM\Events;
8
use Zenstruck\Foundry\Tests\Fixtures\Entity\Comment;
9
10
class CommentEventSubscriber implements EventSubscriberInterface
11
{
12
    public const COMMENT_BODY = 'test-event';
13
    public const NEW_COMMENT_BODY = 'new body';
14
15
    public function getSubscribedEvents(): array
16
    {
17
        return [Events::prePersist];
18
    }
19
20
    public function prePersist(LifecycleEventArgs $event): void
21
    {
22
        if (
23
            !$event->getObject() instanceof Comment
24
            || self::COMMENT_BODY !== $event->getObject()->getBody()
25
        ) {
26
            return;
27
        }
28
29
        $event->getObject()->setBody(self::NEW_COMMENT_BODY);
30
    }
31
}
32