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

CommentEventListener::prePersist()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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