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

CommentEventListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A prePersist() 0 10 3
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