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

PostEventSubscriber   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prePersist() 0 10 3
A getSubscribedEvents() 0 3 1
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Fixtures\Event;
4
5
use Doctrine\Common\EventSubscriber;
6
use Doctrine\ORM\Event\LifecycleEventArgs;
7
use Doctrine\ORM\Events;
8
use Zenstruck\Foundry\Tests\Fixtures\Entity\Post;
9
10
class PostEventSubscriber implements EventSubscriber
11
{
12
    public const TITLE_VALUE = 'title value from event subscriber';
13
    public const NEW_TITLE_VALUE = 'new title value from event subscriber';
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 Post
24
            || self::TITLE_VALUE !== $event->getObject()->getTitle()
25
        ) {
26
            return;
27
        }
28
29
        $event->getObject()->setTitle(self::NEW_TITLE_VALUE);
30
    }
31
}
32