CommentListener::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Mykees\CommentBundle\Listener;
4
5
use Doctrine\ORM\Event\LifecycleEventArgs;
6
use Mykees\CommentBundle\Interfaces\IsCommentable;
7
use Doctrine\ORM\Events;
8
use Mykees\CommentBundle\Manager\CommentQueryManager;
9
use Doctrine\Common\Persistence\ManagerRegistry;
10
11
class CommentListener{
12
13
14
	public $container;
15
	public $entity;
16
	public $fos_user;
17
	public $class;
18
	public $managerRegistry;
19
	public $depth;
20
21
22
	public function __construct(ManagerRegistry $managerRegistry, $class, $fos_user_class, $depth)
23
	{
24
		$this->managerRegistry = $managerRegistry;
25
		$this->class = $class;
26
		$this->fos_user  = $fos_user_class;
27
		$this->depth = $depth;
28
	}
29
30
31
	public function preRemove(LifecycleEventArgs $args)
32
	{
33
		$model = $args->getEntity();
34
35
		if($model instanceof IsCommentable)
36
		{
37
			$manager = new CommentQueryManager($this->managerRegistry,$this->class,$this->depth);
38
			$manager->preDeleteComment($model);
39
		}
40
	}
41
42
43
	public function getSubscribedEvents()
44
	{
45
		return [
46
			Events::preRemove
47
		];
48
	}
49
50
}
51