Passed
Push — master ( e769ca...f1e182 )
by Stone
04:38
created

CommentCreatedSubscriber   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 6
dl 0
loc 20
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerCommentToDatabase() 0 4 1
A getSubscribedEvents() 0 5 1
1
<?php
2
3
namespace App\EventSubscriber\Comment;
4
5
use App\Event\Comment\CommentCreatedEvent;
6
use App\Event\Comment\CommentEditedEvent;
7
use App\Event\Comment\CommentEvent;
8
use App\FlashMessage\FlashMessageCategory;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
11
class CommentCreatedSubscriber extends CommentSubscriber implements EventSubscriberInterface
12
{
13
    /**
14
     * Send Comment to the database and set a flash message
15
     * @param CommentEvent $event
16
     */
17
    public function registerCommentToDatabase(CommentEvent $event)
18
    {
19
        $this->sendToDatabase($event);
20
        $this->addFlash(FlashMessageCategory::SUCCESS, 'Comment saved');
21
    }
22
23
    /**
24
     * @return array The event names to listen to
25
     */
26
    public static function getSubscribedEvents()
27
    {
28
        return [
29
            CommentCreatedEvent::NAME => 'registerCommentToDatabase',
30
            CommentEditedEvent::NAME => 'registerCommentToDatabase',
31
        ];
32
    }
33
}