Passed
Branch feature/comments (12b220)
by Stone
04:53
created

CommentDeletedSubscriber   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteCommentFromDatabase() 0 6 1
A getSubscribedEvents() 0 4 1
1
<?php
2
3
namespace App\EventSubscriber\Comment;
4
5
use App\Entity\Comment;
6
use App\Event\Comment\CommentDeletedEvent;
7
use App\FlashMessage\FlashMessageCategory;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10
class CommentDeletedSubscriber extends CommentSubscriber implements EventSubscriberInterface
11
{
12
    /**
13
     * Deletes a comment
14
     * @param CommentDeletedEvent $event
15
     */
16
    public function deleteCommentFromDatabase(CommentDeletedEvent $event)
17
    {
18
        /** @var Comment $comment */
19
        $comment = $event->getEntity();
0 ignored issues
show
Unused Code introduced by
The assignment to $comment is dead and can be removed.
Loading history...
20
        $this->deleteFromDatabase($event);
21
        $this->addFlash(FlashMessageCategory::SUCCESS, 'Comment Deleted');
22
    }
23
24
    /**
25
     * @return array The event names to listen to
26
     */
27
    public static function getSubscribedEvents()
28
    {
29
        return [
30
            CommentDeletedEvent::NAME => 'deleteCommentFromDatabase'
31
        ];
32
    }
33
}