Completed
Push — master ( 205102...ec6600 )
by Rafidison
02:47
created
Interfaces/HasUserInterface.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,6 +12,6 @@
 block discarded – undo
12 12
 
13 13
 interface HasUserInterface {
14 14
 
15
-	public function getUser();
16
-	public function setUser(UserInterface $user);
15
+    public function getUser();
16
+    public function setUser(UserInterface $user);
17 17
 }
Please login to merge, or discard this patch.
Interfaces/IsCommentable.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: Rafidion Michael
5
- * Date: 03/09/2015
6
- * Time: 12:00
7
- */
3
+     * Created by PhpStorm.
4
+     * User: Rafidion Michael
5
+     * Date: 03/09/2015
6
+     * Time: 12:00
7
+     */
8 8
 
9 9
 namespace Mykees\CommentBundle\Interfaces;
10 10
 
11 11
 
12 12
 interface IsCommentable {
13
-	public function getId();
13
+    public function getId();
14 14
 }
Please login to merge, or discard this patch.
Listener/CommentListener.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -11,40 +11,40 @@
 block discarded – undo
11 11
 class CommentListener{
12 12
 
13 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
-	}
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 49
 
50 50
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use Mykees\CommentBundle\Manager\CommentQueryManager;
9 9
 use Doctrine\Common\Persistence\ManagerRegistry;
10 10
 
11
-class CommentListener{
11
+class CommentListener {
12 12
 
13 13
 
14 14
 	public $container;
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	{
24 24
 		$this->managerRegistry = $managerRegistry;
25 25
 		$this->class = $class;
26
-		$this->fos_user  = $fos_user_class;
26
+		$this->fos_user = $fos_user_class;
27 27
 		$this->depth = $depth;
28 28
 	}
29 29
 
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 	{
33 33
 		$model = $args->getEntity();
34 34
 
35
-		if($model instanceof IsCommentable)
35
+		if ($model instanceof IsCommentable)
36 36
 		{
37
-			$manager = new CommentQueryManager($this->managerRegistry,$this->class,$this->depth);
37
+			$manager = new CommentQueryManager($this->managerRegistry, $this->class, $this->depth);
38 38
 			$manager->preDeleteComment($model);
39 39
 		}
40 40
 	}
Please login to merge, or discard this patch.
Manager/CommentManager.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -18,82 +18,82 @@
 block discarded – undo
18 18
 
19 19
 class CommentManager extends Manager{
20 20
 
21
-	protected $formFactory;
22
-	protected $router;
23
-	protected $comment_class;
24
-	protected $repository;
25
-	protected $session;
26
-	protected $formType;
27
-
28
-	public function __construct(FormFactory $formFactory, Router $router, Session $session, CommentFormType $formType, $class)
29
-	{
30
-		$this->formFactory  = $formFactory;
31
-		$this->router       = $router;
32
-		$this->comment_class = $class;
33
-		$this->formType = $formType;
34
-		$this->session = $session;
35
-	}
36
-
37
-
38
-	/**
39
-	 * Create Comment Form
40
-	 * @param IsCommentable $model
41
-	 * @param array $labels
42
-	 * @param null $success_message
43
-	 * @return \Symfony\Component\Form\Form
44
-	 */
45
-	public function createForm(IsCommentable $model, $labels = [], $success_message=null)
46
-	{
47
-		$dataForm = $this->session->get('form_comment_data');
48
-		$model_name  = $this->getClassShortName($model);
49
-		$route    = $this->router->generate('mykees_comment_manage');
50
-		$comment  = new $this->comment_class;
51
-		$comment->setModel($model_name);
52
-		$comment->setModelId($model->getId());
53
-
54
-		$this->formType->username = !empty($labels['username']) ? $labels['username'] : false;
55
-		$this->formType->email    = !empty($labels['email']) ? $labels['email'] : false;
56
-		$this->formType->content  = !empty($labels['content']) ? $labels['content'] : false;
57
-
58
-
59
-		if($this->session->has('success_message')) { $this->session->remove('success_message'); }
60
-		if($success_message) { $this->session->set('success_message',$success_message); }
61
-
62
-		$form = $this->formFactory->create(
63
-			$this->formType,
64
-			$comment,
65
-			['action'=> $route,'method'=> 'POST']
66
-		);
67
-
68
-		if( !empty($dataForm) ){
69
-			$form->submit($dataForm);
70
-			$this->session->remove('form_comment_data');
71
-		}
72
-
73
-		return $form;
74
-	}
75
-
76
-	/**
77
-	 * Verify if the comment is a spam
78
-	 * @param $comment
79
-	 * @param Request $request
80
-	 * @param $akismetInit
81
-	 * @return bool
82
-	 * @throws \Symfony\Component\Config\Definition\Exception\Exception
83
-	 */
84
-	public function isSpam($comment, Request $request, $akismetInit)
85
-	{
86
-		if($akismetInit){
87
-			$akismet     = new Akismet($akismetInit['website'],$akismetInit['api_key'],$request);
88
-
89
-			$akismet->setCommentAuthor($comment->getUsername());
90
-			$akismet->setCommentAuthorEmail($comment->getEmail());
91
-			$akismet->setCommentContent($comment->getContent());
92
-			$akismet->setUserIP($comment->getIp());
93
-
94
-			return $akismet->isCommentSpam($request);
95
-		}
96
-		return false;
97
-	}
21
+    protected $formFactory;
22
+    protected $router;
23
+    protected $comment_class;
24
+    protected $repository;
25
+    protected $session;
26
+    protected $formType;
27
+
28
+    public function __construct(FormFactory $formFactory, Router $router, Session $session, CommentFormType $formType, $class)
29
+    {
30
+        $this->formFactory  = $formFactory;
31
+        $this->router       = $router;
32
+        $this->comment_class = $class;
33
+        $this->formType = $formType;
34
+        $this->session = $session;
35
+    }
36
+
37
+
38
+    /**
39
+     * Create Comment Form
40
+     * @param IsCommentable $model
41
+     * @param array $labels
42
+     * @param null $success_message
43
+     * @return \Symfony\Component\Form\Form
44
+     */
45
+    public function createForm(IsCommentable $model, $labels = [], $success_message=null)
46
+    {
47
+        $dataForm = $this->session->get('form_comment_data');
48
+        $model_name  = $this->getClassShortName($model);
49
+        $route    = $this->router->generate('mykees_comment_manage');
50
+        $comment  = new $this->comment_class;
51
+        $comment->setModel($model_name);
52
+        $comment->setModelId($model->getId());
53
+
54
+        $this->formType->username = !empty($labels['username']) ? $labels['username'] : false;
55
+        $this->formType->email    = !empty($labels['email']) ? $labels['email'] : false;
56
+        $this->formType->content  = !empty($labels['content']) ? $labels['content'] : false;
57
+
58
+
59
+        if($this->session->has('success_message')) { $this->session->remove('success_message'); }
60
+        if($success_message) { $this->session->set('success_message',$success_message); }
61
+
62
+        $form = $this->formFactory->create(
63
+            $this->formType,
64
+            $comment,
65
+            ['action'=> $route,'method'=> 'POST']
66
+        );
67
+
68
+        if( !empty($dataForm) ){
69
+            $form->submit($dataForm);
70
+            $this->session->remove('form_comment_data');
71
+        }
72
+
73
+        return $form;
74
+    }
75
+
76
+    /**
77
+     * Verify if the comment is a spam
78
+     * @param $comment
79
+     * @param Request $request
80
+     * @param $akismetInit
81
+     * @return bool
82
+     * @throws \Symfony\Component\Config\Definition\Exception\Exception
83
+     */
84
+    public function isSpam($comment, Request $request, $akismetInit)
85
+    {
86
+        if($akismetInit){
87
+            $akismet     = new Akismet($akismetInit['website'],$akismetInit['api_key'],$request);
88
+
89
+            $akismet->setCommentAuthor($comment->getUsername());
90
+            $akismet->setCommentAuthorEmail($comment->getEmail());
91
+            $akismet->setCommentContent($comment->getContent());
92
+            $akismet->setUserIP($comment->getIp());
93
+
94
+            return $akismet->isCommentSpam($request);
95
+        }
96
+        return false;
97
+    }
98 98
 
99 99
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 use Symfony\Component\HttpFoundation\Session\Session;
17 17
 use Mykees\CommentBundle\Form\Type\CommentFormType;
18 18
 
19
-class CommentManager extends Manager{
19
+class CommentManager extends Manager {
20 20
 
21 21
 	protected $formFactory;
22 22
 	protected $router;
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 	 * @param null $success_message
43 43
 	 * @return \Symfony\Component\Form\Form
44 44
 	 */
45
-	public function createForm(IsCommentable $model, $labels = [], $success_message=null)
45
+	public function createForm(IsCommentable $model, $labels = [], $success_message = null)
46 46
 	{
47 47
 		$dataForm = $this->session->get('form_comment_data');
48
-		$model_name  = $this->getClassShortName($model);
48
+		$model_name = $this->getClassShortName($model);
49 49
 		$route    = $this->router->generate('mykees_comment_manage');
50 50
 		$comment  = new $this->comment_class;
51 51
 		$comment->setModel($model_name);
@@ -56,16 +56,16 @@  discard block
 block discarded – undo
56 56
 		$this->formType->content  = !empty($labels['content']) ? $labels['content'] : false;
57 57
 
58 58
 
59
-		if($this->session->has('success_message')) { $this->session->remove('success_message'); }
60
-		if($success_message) { $this->session->set('success_message',$success_message); }
59
+		if ($this->session->has('success_message')) { $this->session->remove('success_message'); }
60
+		if ($success_message) { $this->session->set('success_message', $success_message); }
61 61
 
62 62
 		$form = $this->formFactory->create(
63 63
 			$this->formType,
64 64
 			$comment,
65
-			['action'=> $route,'method'=> 'POST']
65
+			['action'=> $route, 'method'=> 'POST']
66 66
 		);
67 67
 
68
-		if( !empty($dataForm) ){
68
+		if (!empty($dataForm)) {
69 69
 			$form->submit($dataForm);
70 70
 			$this->session->remove('form_comment_data');
71 71
 		}
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 	 */
84 84
 	public function isSpam($comment, Request $request, $akismetInit)
85 85
 	{
86
-		if($akismetInit){
87
-			$akismet     = new Akismet($akismetInit['website'],$akismetInit['api_key'],$request);
86
+		if ($akismetInit) {
87
+			$akismet = new Akismet($akismetInit['website'], $akismetInit['api_key'], $request);
88 88
 
89 89
 			$akismet->setCommentAuthor($comment->getUsername());
90 90
 			$akismet->setCommentAuthorEmail($comment->getEmail());
Please login to merge, or discard this patch.
Manager/CommentQueryManager.php 3 patches
Indentation   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -13,333 +13,333 @@
 block discarded – undo
13 13
 
14 14
 class CommentQueryManager extends Manager{
15 15
 
16
-	private $repository;
17
-	private $comment_class;
18
-	private $depth;
19
-	private $depth_reached;
20
-
21
-	public function __construct(ManagerRegistry $managerRegistry, $class, $depth)
22
-	{
23
-		$this->comment_class = $class;
24
-		$this->repository = $managerRegistry->getRepository($this->comment_class);
25
-		$this->depth = $depth;
26
-	}
27
-
28
-
29
-	/**
30
-	 * Find one comment
31
-	 * @param $id
32
-	 * @param null $model_name
33
-	 * @param int $model_id
34
-	 * @return mixed
35
-	 */
36
-	public function findOneComment($id, $model_name=null,$model_id=0)
37
-	{
38
-		$is_join = method_exists($this->comment_class,'getUser') ? true : false;
39
-		$qb = $this->repository->createQueryBuilder('c');
40
-
41
-		return $this->oneCommentQueryResult($qb, $id, $model_name, $model_id, $is_join);
42
-	}
43
-
44
-
45
-	/**
46
-	 * Find a comment by model referer
47
-	 * @param $id
48
-	 * @param IsCommentable $model
49
-	 * @return mixed
50
-	 */
51
-	public function findOneCommentByReferer($id,IsCommentable $model)
52
-	{
53
-		$model_name  = $this->getClassShortName( $model );
54
-		$model_id  = $model->getId();
55
-		$qb = $this->repository->createQueryBuilder('c');
56
-		$is_join = method_exists($this->comment_class,'getUser') ? true : false;
57
-
58
-		return $this->oneCommentQueryResult($qb, $id, $model_name, $model_id, $is_join);
59
-	}
60
-
61
-	/**
62
-	 * Find all comments for an entity
63
-	 * @param IsCommentable $model
64
-	 * @param bool $get_by_id
65
-	 * @return mixed
66
-	 */
67
-	public function findComments(IsCommentable $model, $get_by_id=false)
68
-	{
69
-		$model_name  = $this->getClassShortName( $model );
70
-		$comments = [];
71
-		$is_join = method_exists($this->comment_class,'getUser') ? true : false;
72
-		$qb = $this->repository->createQueryBuilder('c');
73
-
74
-		$comments['comments'] = $this->commentQueryResult($qb, $model_name, $model->getId(), $is_join);
75
-		$comments['count'] = count($comments['comments']);
76
-
77
-		return $this->buildCommentStructure($comments,$get_by_id);
78
-	}
79
-
80
-
81
-	/**
82
-	 * Find all comments for an entity
83
-	 * @param $model_name
84
-	 * @param $model_id
85
-	 * @param bool $get_by_id
86
-	 * @return mixed
87
-	 */
88
-	public function findCommentsByModelAndId($model_name, $model_id, $get_by_id=false)
89
-	{
90
-		$comments = [];
91
-		$is_join = method_exists($this->comment_class,'getUser') ? true : false;
92
-		$qb = $this->repository->createQueryBuilder('c');
93
-
94
-		$comments['comments'] = $this->commentQueryResult($qb, $model_name, $model_id, $is_join);
95
-		$comments['count'] = count($comments['comments']);
96
-
97
-		return $this->buildCommentStructure($comments,$get_by_id);
98
-	}
99
-
100
-
101
-	/**
102
-	 * Build Comment Structure
103
-	 * @param $comments
104
-	 * @param bool $get_by_id
105
-	 * @return mixed
106
-	 */
107
-	private function buildCommentStructure($comments, $get_by_id=false)
108
-	{
109
-		$comments_by_id = [];
110
-		return $this->build($comments,$comments_by_id,$get_by_id);
111
-	}
112
-
113
-
114
-	private function build($comments,$comments_by_id, $get_by_id)
115
-	{
116
-		foreach($comments['comments'] as $comment)
117
-		{
118
-			$comments_by_id[$comment->getId()] = $comment;
119
-			$comment->setDepth($this->depth);
120
-		}
121
-
122
-		//Comment parent and children
123
-		foreach($comments['comments'] as $k=>$comment)
124
-		{
125
-			if($this->depth > 0 && $comment->getParentId() > 0)
126
-			{
127
-				$parent_id = $this->depthComment($comments_by_id,$comment->getId());
128
-
129
-				//Si la pronfondeur atteinte est plus petite que la profondeur definis
130
-				//alors la réponse aura l'id du commentaire
131
-				//Sinon
132
-				//la réponse aura l'id du parent
133
-				if($this->depth_reached < $this->depth)
134
-				{
135
-					$comment->setDepth($comment->getId());
136
-				}else{
137
-					$comment->setDepth($parent_id);
138
-				}
139
-				$comment->setDepthReached($this->depth_reached);
140
-				$comments_by_id[$parent_id]->setChildren($comment);
141
-				unset($comments['comments'][$k]);
142
-
143
-			}else if($this->depth == 0){
144
-				$comment->setDepth(0);
145
-			}else{
146
-				$comment->setDepth($comment->getId());
147
-			}
148
-
149
-		}
150
-
151
-		if($get_by_id)
152
-		{
153
-			return $comments_by_id;
154
-		}else{
155
-			return $comments;
156
-		}
157
-	}
158
-
159
-	/**
160
-	 * config depth of comments
161
-	 * @param $comments_by_id
162
-	 * @param $comment_id
163
-	 * @return mixed
164
-	 */
165
-	private function depthComment($comments_by_id,$comment_id)
166
-	{
167
-		$parent_id=[];
168
-		$index = $comment_id;
169
-		$parent = true;
170
-		$depth_reached = 0;
171
-
172
-		while($parent)
173
-		{
174
-			$comment = $comments_by_id[$index];
175
-			if($comment->getParentId())
176
-			{
177
-				$parent_id[] = $comments_by_id[$index]->getParentId();
178
-				$index = $comments_by_id[$index]->getParentId();
179
-				$depth_reached++;
180
-			}else{
181
-				$parent = false;
182
-			}
183
-		}
184
-		$this->depth_reached = $depth_reached;
185
-		$array_reverse = array_reverse($parent_id);
186
-
187
-		return $this->depth < count($array_reverse) ? $array_reverse[$this->depth-1] : end($array_reverse);
188
-	}
189
-
190
-
191
-	/**
192
-	 * Retrieve all comments
193
-	 * @param array $criteria
194
-	 * @param null $orderBy
195
-	 * @param null $limit
196
-	 * @param null $offset
197
-	 * @return array
198
-	 */
199
-	public function findAllComments(array $criteria=[],$orderBy=null,$limit=null,$offset=null)
200
-	{
201
-		if(!empty($criteria) || isset($orderBy) || isset($limit) || isset($offset))
202
-		{
203
-			return $this->repository->findBy($criteria,$orderBy,$limit,$offset);
204
-		}else{
205
-			return $this->repository->findAll();
206
-		}
207
-	}
208
-
209
-
210
-	/**
211
-	 * @param $qb
212
-	 * @param $model_name
213
-	 * @param $model_id
214
-	 * @param $is_join
215
-	 * @return mixed
216
-	 */
217
-	private function commentQueryResult($qb, $model_name, $model_id, $is_join)
218
-	{
219
-		if($is_join)
220
-		{
221
-			$qb
222
-				->leftJoin('c.user','u')
223
-				->addSelect('u')
224
-			;
225
-		}
226
-
227
-		return $qb
228
-			->where("c.model = :ref")
229
-			->setParameter('ref',$model_name)
230
-			->andWhere("c.modelId = :ref_id")
231
-			->setParameter('ref_id',$model_id)
232
-			->orderBy('c.createdAt', 'DESC')
233
-			->getQuery()
234
-			->getResult()
235
-		;
236
-	}
237
-
238
-	private function oneCommentQueryResult($qb, $id, $model_name, $model_id, $is_join)
239
-	{
240
-		if($is_join)
241
-		{
242
-			$qb
243
-				->leftJoin('c.user','u')
244
-				->addSelect('u')
245
-			;
246
-		}
247
-		$qb->where('c.id = :id')
248
-			->setParameter('id',$id)
249
-		;
250
-
251
-		if($model_name)
252
-		{
253
-			$qb->andWhere("c.model = :ref")
254
-				->setParameter('ref',$model_name)
255
-			;
256
-		}
257
-		if($model_id > 0)
258
-		{
259
-			$qb->andWhere("c.modelId = :ref_id")
260
-				->setParameter('ref_id',$model_id)
261
-			;
262
-		}
263
-
264
-		return $qb->getQuery()->getOneOrNullResult();
265
-	}
266
-
267
-
268
-	/**
269
-	 * @param $ids
270
-	 * @return mixed
271
-	 */
272
-	public function deleteByCommentIds($ids)
273
-	{
274
-		$comment_class = $this->classRepository($this->comment_class);
275
-
276
-		return $this->repository
277
-			->createQueryBuilder('c')
278
-			->delete($comment_class,'c')
279
-			->where("c.id IN(:ids)")
280
-			->setParameter('ids', array_values($ids))
281
-			->getQuery()
282
-			->execute()
283
-		;
284
-	}
285
-
286
-
287
-	/**
288
-	 * Delete a comment by id
289
-	 * @param $id
290
-	 * @return mixed
291
-	 */
292
-	public function deleteComment($id)
293
-	{
294
-		$comment_class = $this->classRepository($this->comment_class);
295
-
296
-		return $this->repository
297
-			->createQueryBuilder('c')
298
-			->delete($comment_class,'c')
299
-			->where("c.id = id")
300
-			->setParameter('id', $id)
301
-			->getQuery()
302
-			->execute()
303
-		;
304
-	}
305
-
306
-
307
-
308
-	/**
309
-	 * Remove ccomment children
310
-	 * @param $comment
311
-	 * @return array
312
-	 */
313
-	public function getChildren($comment)
314
-	{
315
-		$children_ids = [];
316
-		foreach($comment->getChildren() as $child)
317
-		{
318
-			$children_ids[] = $child->getId();
319
-			if($child->getChildren())
320
-			{
321
-				$children_ids = array_merge($children_ids, $this->getChildren($child));
322
-			}
323
-		}
324
-
325
-		return $children_ids;
326
-	}
327
-
328
-	/**
329
-	 * Pre delete comment
330
-	 * @param IsCommentable $referer
331
-	 * @return bool
332
-	 */
333
-	public function preDeleteComment(IsCommentable $referer)
334
-	{
335
-		$comments = $this->findComments($referer, true);
336
-		foreach($comments as $k=>$comment)
337
-		{
338
-			$children_ids = $this->getChildren($comment);
339
-			array_push($children_ids,$k);
340
-
341
-			$this->deleteByCommentIds($children_ids);
342
-		}
343
-		return true;
344
-	}
16
+    private $repository;
17
+    private $comment_class;
18
+    private $depth;
19
+    private $depth_reached;
20
+
21
+    public function __construct(ManagerRegistry $managerRegistry, $class, $depth)
22
+    {
23
+        $this->comment_class = $class;
24
+        $this->repository = $managerRegistry->getRepository($this->comment_class);
25
+        $this->depth = $depth;
26
+    }
27
+
28
+
29
+    /**
30
+     * Find one comment
31
+     * @param $id
32
+     * @param null $model_name
33
+     * @param int $model_id
34
+     * @return mixed
35
+     */
36
+    public function findOneComment($id, $model_name=null,$model_id=0)
37
+    {
38
+        $is_join = method_exists($this->comment_class,'getUser') ? true : false;
39
+        $qb = $this->repository->createQueryBuilder('c');
40
+
41
+        return $this->oneCommentQueryResult($qb, $id, $model_name, $model_id, $is_join);
42
+    }
43
+
44
+
45
+    /**
46
+     * Find a comment by model referer
47
+     * @param $id
48
+     * @param IsCommentable $model
49
+     * @return mixed
50
+     */
51
+    public function findOneCommentByReferer($id,IsCommentable $model)
52
+    {
53
+        $model_name  = $this->getClassShortName( $model );
54
+        $model_id  = $model->getId();
55
+        $qb = $this->repository->createQueryBuilder('c');
56
+        $is_join = method_exists($this->comment_class,'getUser') ? true : false;
57
+
58
+        return $this->oneCommentQueryResult($qb, $id, $model_name, $model_id, $is_join);
59
+    }
60
+
61
+    /**
62
+     * Find all comments for an entity
63
+     * @param IsCommentable $model
64
+     * @param bool $get_by_id
65
+     * @return mixed
66
+     */
67
+    public function findComments(IsCommentable $model, $get_by_id=false)
68
+    {
69
+        $model_name  = $this->getClassShortName( $model );
70
+        $comments = [];
71
+        $is_join = method_exists($this->comment_class,'getUser') ? true : false;
72
+        $qb = $this->repository->createQueryBuilder('c');
73
+
74
+        $comments['comments'] = $this->commentQueryResult($qb, $model_name, $model->getId(), $is_join);
75
+        $comments['count'] = count($comments['comments']);
76
+
77
+        return $this->buildCommentStructure($comments,$get_by_id);
78
+    }
79
+
80
+
81
+    /**
82
+     * Find all comments for an entity
83
+     * @param $model_name
84
+     * @param $model_id
85
+     * @param bool $get_by_id
86
+     * @return mixed
87
+     */
88
+    public function findCommentsByModelAndId($model_name, $model_id, $get_by_id=false)
89
+    {
90
+        $comments = [];
91
+        $is_join = method_exists($this->comment_class,'getUser') ? true : false;
92
+        $qb = $this->repository->createQueryBuilder('c');
93
+
94
+        $comments['comments'] = $this->commentQueryResult($qb, $model_name, $model_id, $is_join);
95
+        $comments['count'] = count($comments['comments']);
96
+
97
+        return $this->buildCommentStructure($comments,$get_by_id);
98
+    }
99
+
100
+
101
+    /**
102
+     * Build Comment Structure
103
+     * @param $comments
104
+     * @param bool $get_by_id
105
+     * @return mixed
106
+     */
107
+    private function buildCommentStructure($comments, $get_by_id=false)
108
+    {
109
+        $comments_by_id = [];
110
+        return $this->build($comments,$comments_by_id,$get_by_id);
111
+    }
112
+
113
+
114
+    private function build($comments,$comments_by_id, $get_by_id)
115
+    {
116
+        foreach($comments['comments'] as $comment)
117
+        {
118
+            $comments_by_id[$comment->getId()] = $comment;
119
+            $comment->setDepth($this->depth);
120
+        }
121
+
122
+        //Comment parent and children
123
+        foreach($comments['comments'] as $k=>$comment)
124
+        {
125
+            if($this->depth > 0 && $comment->getParentId() > 0)
126
+            {
127
+                $parent_id = $this->depthComment($comments_by_id,$comment->getId());
128
+
129
+                //Si la pronfondeur atteinte est plus petite que la profondeur definis
130
+                //alors la réponse aura l'id du commentaire
131
+                //Sinon
132
+                //la réponse aura l'id du parent
133
+                if($this->depth_reached < $this->depth)
134
+                {
135
+                    $comment->setDepth($comment->getId());
136
+                }else{
137
+                    $comment->setDepth($parent_id);
138
+                }
139
+                $comment->setDepthReached($this->depth_reached);
140
+                $comments_by_id[$parent_id]->setChildren($comment);
141
+                unset($comments['comments'][$k]);
142
+
143
+            }else if($this->depth == 0){
144
+                $comment->setDepth(0);
145
+            }else{
146
+                $comment->setDepth($comment->getId());
147
+            }
148
+
149
+        }
150
+
151
+        if($get_by_id)
152
+        {
153
+            return $comments_by_id;
154
+        }else{
155
+            return $comments;
156
+        }
157
+    }
158
+
159
+    /**
160
+     * config depth of comments
161
+     * @param $comments_by_id
162
+     * @param $comment_id
163
+     * @return mixed
164
+     */
165
+    private function depthComment($comments_by_id,$comment_id)
166
+    {
167
+        $parent_id=[];
168
+        $index = $comment_id;
169
+        $parent = true;
170
+        $depth_reached = 0;
171
+
172
+        while($parent)
173
+        {
174
+            $comment = $comments_by_id[$index];
175
+            if($comment->getParentId())
176
+            {
177
+                $parent_id[] = $comments_by_id[$index]->getParentId();
178
+                $index = $comments_by_id[$index]->getParentId();
179
+                $depth_reached++;
180
+            }else{
181
+                $parent = false;
182
+            }
183
+        }
184
+        $this->depth_reached = $depth_reached;
185
+        $array_reverse = array_reverse($parent_id);
186
+
187
+        return $this->depth < count($array_reverse) ? $array_reverse[$this->depth-1] : end($array_reverse);
188
+    }
189
+
190
+
191
+    /**
192
+     * Retrieve all comments
193
+     * @param array $criteria
194
+     * @param null $orderBy
195
+     * @param null $limit
196
+     * @param null $offset
197
+     * @return array
198
+     */
199
+    public function findAllComments(array $criteria=[],$orderBy=null,$limit=null,$offset=null)
200
+    {
201
+        if(!empty($criteria) || isset($orderBy) || isset($limit) || isset($offset))
202
+        {
203
+            return $this->repository->findBy($criteria,$orderBy,$limit,$offset);
204
+        }else{
205
+            return $this->repository->findAll();
206
+        }
207
+    }
208
+
209
+
210
+    /**
211
+     * @param $qb
212
+     * @param $model_name
213
+     * @param $model_id
214
+     * @param $is_join
215
+     * @return mixed
216
+     */
217
+    private function commentQueryResult($qb, $model_name, $model_id, $is_join)
218
+    {
219
+        if($is_join)
220
+        {
221
+            $qb
222
+                ->leftJoin('c.user','u')
223
+                ->addSelect('u')
224
+            ;
225
+        }
226
+
227
+        return $qb
228
+            ->where("c.model = :ref")
229
+            ->setParameter('ref',$model_name)
230
+            ->andWhere("c.modelId = :ref_id")
231
+            ->setParameter('ref_id',$model_id)
232
+            ->orderBy('c.createdAt', 'DESC')
233
+            ->getQuery()
234
+            ->getResult()
235
+        ;
236
+    }
237
+
238
+    private function oneCommentQueryResult($qb, $id, $model_name, $model_id, $is_join)
239
+    {
240
+        if($is_join)
241
+        {
242
+            $qb
243
+                ->leftJoin('c.user','u')
244
+                ->addSelect('u')
245
+            ;
246
+        }
247
+        $qb->where('c.id = :id')
248
+            ->setParameter('id',$id)
249
+        ;
250
+
251
+        if($model_name)
252
+        {
253
+            $qb->andWhere("c.model = :ref")
254
+                ->setParameter('ref',$model_name)
255
+            ;
256
+        }
257
+        if($model_id > 0)
258
+        {
259
+            $qb->andWhere("c.modelId = :ref_id")
260
+                ->setParameter('ref_id',$model_id)
261
+            ;
262
+        }
263
+
264
+        return $qb->getQuery()->getOneOrNullResult();
265
+    }
266
+
267
+
268
+    /**
269
+     * @param $ids
270
+     * @return mixed
271
+     */
272
+    public function deleteByCommentIds($ids)
273
+    {
274
+        $comment_class = $this->classRepository($this->comment_class);
275
+
276
+        return $this->repository
277
+            ->createQueryBuilder('c')
278
+            ->delete($comment_class,'c')
279
+            ->where("c.id IN(:ids)")
280
+            ->setParameter('ids', array_values($ids))
281
+            ->getQuery()
282
+            ->execute()
283
+        ;
284
+    }
285
+
286
+
287
+    /**
288
+     * Delete a comment by id
289
+     * @param $id
290
+     * @return mixed
291
+     */
292
+    public function deleteComment($id)
293
+    {
294
+        $comment_class = $this->classRepository($this->comment_class);
295
+
296
+        return $this->repository
297
+            ->createQueryBuilder('c')
298
+            ->delete($comment_class,'c')
299
+            ->where("c.id = id")
300
+            ->setParameter('id', $id)
301
+            ->getQuery()
302
+            ->execute()
303
+        ;
304
+    }
305
+
306
+
307
+
308
+    /**
309
+     * Remove ccomment children
310
+     * @param $comment
311
+     * @return array
312
+     */
313
+    public function getChildren($comment)
314
+    {
315
+        $children_ids = [];
316
+        foreach($comment->getChildren() as $child)
317
+        {
318
+            $children_ids[] = $child->getId();
319
+            if($child->getChildren())
320
+            {
321
+                $children_ids = array_merge($children_ids, $this->getChildren($child));
322
+            }
323
+        }
324
+
325
+        return $children_ids;
326
+    }
327
+
328
+    /**
329
+     * Pre delete comment
330
+     * @param IsCommentable $referer
331
+     * @return bool
332
+     */
333
+    public function preDeleteComment(IsCommentable $referer)
334
+    {
335
+        $comments = $this->findComments($referer, true);
336
+        foreach($comments as $k=>$comment)
337
+        {
338
+            $children_ids = $this->getChildren($comment);
339
+            array_push($children_ids,$k);
340
+
341
+            $this->deleteByCommentIds($children_ids);
342
+        }
343
+        return true;
344
+    }
345 345
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use Doctrine\Common\Persistence\ManagerRegistry;
12 12
 use Mykees\CommentBundle\Interfaces\IsCommentable;
13 13
 
14
-class CommentQueryManager extends Manager{
14
+class CommentQueryManager extends Manager {
15 15
 
16 16
 	private $repository;
17 17
 	private $comment_class;
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
 	 * @param int $model_id
34 34
 	 * @return mixed
35 35
 	 */
36
-	public function findOneComment($id, $model_name=null,$model_id=0)
36
+	public function findOneComment($id, $model_name = null, $model_id = 0)
37 37
 	{
38
-		$is_join = method_exists($this->comment_class,'getUser') ? true : false;
38
+		$is_join = method_exists($this->comment_class, 'getUser') ? true : false;
39 39
 		$qb = $this->repository->createQueryBuilder('c');
40 40
 
41 41
 		return $this->oneCommentQueryResult($qb, $id, $model_name, $model_id, $is_join);
@@ -48,12 +48,12 @@  discard block
 block discarded – undo
48 48
 	 * @param IsCommentable $model
49 49
 	 * @return mixed
50 50
 	 */
51
-	public function findOneCommentByReferer($id,IsCommentable $model)
51
+	public function findOneCommentByReferer($id, IsCommentable $model)
52 52
 	{
53
-		$model_name  = $this->getClassShortName( $model );
54
-		$model_id  = $model->getId();
53
+		$model_name = $this->getClassShortName($model);
54
+		$model_id = $model->getId();
55 55
 		$qb = $this->repository->createQueryBuilder('c');
56
-		$is_join = method_exists($this->comment_class,'getUser') ? true : false;
56
+		$is_join = method_exists($this->comment_class, 'getUser') ? true : false;
57 57
 
58 58
 		return $this->oneCommentQueryResult($qb, $id, $model_name, $model_id, $is_join);
59 59
 	}
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
 	 * @param bool $get_by_id
65 65
 	 * @return mixed
66 66
 	 */
67
-	public function findComments(IsCommentable $model, $get_by_id=false)
67
+	public function findComments(IsCommentable $model, $get_by_id = false)
68 68
 	{
69
-		$model_name  = $this->getClassShortName( $model );
69
+		$model_name = $this->getClassShortName($model);
70 70
 		$comments = [];
71
-		$is_join = method_exists($this->comment_class,'getUser') ? true : false;
71
+		$is_join = method_exists($this->comment_class, 'getUser') ? true : false;
72 72
 		$qb = $this->repository->createQueryBuilder('c');
73 73
 
74 74
 		$comments['comments'] = $this->commentQueryResult($qb, $model_name, $model->getId(), $is_join);
75 75
 		$comments['count'] = count($comments['comments']);
76 76
 
77
-		return $this->buildCommentStructure($comments,$get_by_id);
77
+		return $this->buildCommentStructure($comments, $get_by_id);
78 78
 	}
79 79
 
80 80
 
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
 	 * @param bool $get_by_id
86 86
 	 * @return mixed
87 87
 	 */
88
-	public function findCommentsByModelAndId($model_name, $model_id, $get_by_id=false)
88
+	public function findCommentsByModelAndId($model_name, $model_id, $get_by_id = false)
89 89
 	{
90 90
 		$comments = [];
91
-		$is_join = method_exists($this->comment_class,'getUser') ? true : false;
91
+		$is_join = method_exists($this->comment_class, 'getUser') ? true : false;
92 92
 		$qb = $this->repository->createQueryBuilder('c');
93 93
 
94 94
 		$comments['comments'] = $this->commentQueryResult($qb, $model_name, $model_id, $is_join);
95 95
 		$comments['count'] = count($comments['comments']);
96 96
 
97
-		return $this->buildCommentStructure($comments,$get_by_id);
97
+		return $this->buildCommentStructure($comments, $get_by_id);
98 98
 	}
99 99
 
100 100
 
@@ -104,54 +104,54 @@  discard block
 block discarded – undo
104 104
 	 * @param bool $get_by_id
105 105
 	 * @return mixed
106 106
 	 */
107
-	private function buildCommentStructure($comments, $get_by_id=false)
107
+	private function buildCommentStructure($comments, $get_by_id = false)
108 108
 	{
109 109
 		$comments_by_id = [];
110
-		return $this->build($comments,$comments_by_id,$get_by_id);
110
+		return $this->build($comments, $comments_by_id, $get_by_id);
111 111
 	}
112 112
 
113 113
 
114
-	private function build($comments,$comments_by_id, $get_by_id)
114
+	private function build($comments, $comments_by_id, $get_by_id)
115 115
 	{
116
-		foreach($comments['comments'] as $comment)
116
+		foreach ($comments['comments'] as $comment)
117 117
 		{
118 118
 			$comments_by_id[$comment->getId()] = $comment;
119 119
 			$comment->setDepth($this->depth);
120 120
 		}
121 121
 
122 122
 		//Comment parent and children
123
-		foreach($comments['comments'] as $k=>$comment)
123
+		foreach ($comments['comments'] as $k=>$comment)
124 124
 		{
125
-			if($this->depth > 0 && $comment->getParentId() > 0)
125
+			if ($this->depth > 0 && $comment->getParentId() > 0)
126 126
 			{
127
-				$parent_id = $this->depthComment($comments_by_id,$comment->getId());
127
+				$parent_id = $this->depthComment($comments_by_id, $comment->getId());
128 128
 
129 129
 				//Si la pronfondeur atteinte est plus petite que la profondeur definis
130 130
 				//alors la réponse aura l'id du commentaire
131 131
 				//Sinon
132 132
 				//la réponse aura l'id du parent
133
-				if($this->depth_reached < $this->depth)
133
+				if ($this->depth_reached < $this->depth)
134 134
 				{
135 135
 					$comment->setDepth($comment->getId());
136
-				}else{
136
+				}else {
137 137
 					$comment->setDepth($parent_id);
138 138
 				}
139 139
 				$comment->setDepthReached($this->depth_reached);
140 140
 				$comments_by_id[$parent_id]->setChildren($comment);
141 141
 				unset($comments['comments'][$k]);
142 142
 
143
-			}else if($this->depth == 0){
143
+			}else if ($this->depth == 0) {
144 144
 				$comment->setDepth(0);
145
-			}else{
145
+			}else {
146 146
 				$comment->setDepth($comment->getId());
147 147
 			}
148 148
 
149 149
 		}
150 150
 
151
-		if($get_by_id)
151
+		if ($get_by_id)
152 152
 		{
153 153
 			return $comments_by_id;
154
-		}else{
154
+		}else {
155 155
 			return $comments;
156 156
 		}
157 157
 	}
@@ -162,29 +162,29 @@  discard block
 block discarded – undo
162 162
 	 * @param $comment_id
163 163
 	 * @return mixed
164 164
 	 */
165
-	private function depthComment($comments_by_id,$comment_id)
165
+	private function depthComment($comments_by_id, $comment_id)
166 166
 	{
167
-		$parent_id=[];
167
+		$parent_id = [];
168 168
 		$index = $comment_id;
169 169
 		$parent = true;
170 170
 		$depth_reached = 0;
171 171
 
172
-		while($parent)
172
+		while ($parent)
173 173
 		{
174 174
 			$comment = $comments_by_id[$index];
175
-			if($comment->getParentId())
175
+			if ($comment->getParentId())
176 176
 			{
177 177
 				$parent_id[] = $comments_by_id[$index]->getParentId();
178 178
 				$index = $comments_by_id[$index]->getParentId();
179 179
 				$depth_reached++;
180
-			}else{
180
+			}else {
181 181
 				$parent = false;
182 182
 			}
183 183
 		}
184 184
 		$this->depth_reached = $depth_reached;
185 185
 		$array_reverse = array_reverse($parent_id);
186 186
 
187
-		return $this->depth < count($array_reverse) ? $array_reverse[$this->depth-1] : end($array_reverse);
187
+		return $this->depth < count($array_reverse) ? $array_reverse[$this->depth - 1] : end($array_reverse);
188 188
 	}
189 189
 
190 190
 
@@ -196,12 +196,12 @@  discard block
 block discarded – undo
196 196
 	 * @param null $offset
197 197
 	 * @return array
198 198
 	 */
199
-	public function findAllComments(array $criteria=[],$orderBy=null,$limit=null,$offset=null)
199
+	public function findAllComments(array $criteria = [], $orderBy = null, $limit = null, $offset = null)
200 200
 	{
201
-		if(!empty($criteria) || isset($orderBy) || isset($limit) || isset($offset))
201
+		if (!empty($criteria) || isset($orderBy) || isset($limit) || isset($offset))
202 202
 		{
203
-			return $this->repository->findBy($criteria,$orderBy,$limit,$offset);
204
-		}else{
203
+			return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
204
+		}else {
205 205
 			return $this->repository->findAll();
206 206
 		}
207 207
 	}
@@ -216,19 +216,19 @@  discard block
 block discarded – undo
216 216
 	 */
217 217
 	private function commentQueryResult($qb, $model_name, $model_id, $is_join)
218 218
 	{
219
-		if($is_join)
219
+		if ($is_join)
220 220
 		{
221 221
 			$qb
222
-				->leftJoin('c.user','u')
222
+				->leftJoin('c.user', 'u')
223 223
 				->addSelect('u')
224 224
 			;
225 225
 		}
226 226
 
227 227
 		return $qb
228 228
 			->where("c.model = :ref")
229
-			->setParameter('ref',$model_name)
229
+			->setParameter('ref', $model_name)
230 230
 			->andWhere("c.modelId = :ref_id")
231
-			->setParameter('ref_id',$model_id)
231
+			->setParameter('ref_id', $model_id)
232 232
 			->orderBy('c.createdAt', 'DESC')
233 233
 			->getQuery()
234 234
 			->getResult()
@@ -237,27 +237,27 @@  discard block
 block discarded – undo
237 237
 
238 238
 	private function oneCommentQueryResult($qb, $id, $model_name, $model_id, $is_join)
239 239
 	{
240
-		if($is_join)
240
+		if ($is_join)
241 241
 		{
242 242
 			$qb
243
-				->leftJoin('c.user','u')
243
+				->leftJoin('c.user', 'u')
244 244
 				->addSelect('u')
245 245
 			;
246 246
 		}
247 247
 		$qb->where('c.id = :id')
248
-			->setParameter('id',$id)
248
+			->setParameter('id', $id)
249 249
 		;
250 250
 
251
-		if($model_name)
251
+		if ($model_name)
252 252
 		{
253 253
 			$qb->andWhere("c.model = :ref")
254
-				->setParameter('ref',$model_name)
254
+				->setParameter('ref', $model_name)
255 255
 			;
256 256
 		}
257
-		if($model_id > 0)
257
+		if ($model_id > 0)
258 258
 		{
259 259
 			$qb->andWhere("c.modelId = :ref_id")
260
-				->setParameter('ref_id',$model_id)
260
+				->setParameter('ref_id', $model_id)
261 261
 			;
262 262
 		}
263 263
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 		return $this->repository
277 277
 			->createQueryBuilder('c')
278
-			->delete($comment_class,'c')
278
+			->delete($comment_class, 'c')
279 279
 			->where("c.id IN(:ids)")
280 280
 			->setParameter('ids', array_values($ids))
281 281
 			->getQuery()
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 
296 296
 		return $this->repository
297 297
 			->createQueryBuilder('c')
298
-			->delete($comment_class,'c')
298
+			->delete($comment_class, 'c')
299 299
 			->where("c.id = id")
300 300
 			->setParameter('id', $id)
301 301
 			->getQuery()
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
 	public function getChildren($comment)
314 314
 	{
315 315
 		$children_ids = [];
316
-		foreach($comment->getChildren() as $child)
316
+		foreach ($comment->getChildren() as $child)
317 317
 		{
318 318
 			$children_ids[] = $child->getId();
319
-			if($child->getChildren())
319
+			if ($child->getChildren())
320 320
 			{
321 321
 				$children_ids = array_merge($children_ids, $this->getChildren($child));
322 322
 			}
@@ -333,10 +333,10 @@  discard block
 block discarded – undo
333 333
 	public function preDeleteComment(IsCommentable $referer)
334 334
 	{
335 335
 		$comments = $this->findComments($referer, true);
336
-		foreach($comments as $k=>$comment)
336
+		foreach ($comments as $k=>$comment)
337 337
 		{
338 338
 			$children_ids = $this->getChildren($comment);
339
-			array_push($children_ids,$k);
339
+			array_push($children_ids, $k);
340 340
 
341 341
 			$this->deleteByCommentIds($children_ids);
342 342
 		}
Please login to merge, or discard this patch.
Braces   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -133,16 +133,16 @@  discard block
 block discarded – undo
133 133
 				if($this->depth_reached < $this->depth)
134 134
 				{
135 135
 					$comment->setDepth($comment->getId());
136
-				}else{
136
+				} else{
137 137
 					$comment->setDepth($parent_id);
138 138
 				}
139 139
 				$comment->setDepthReached($this->depth_reached);
140 140
 				$comments_by_id[$parent_id]->setChildren($comment);
141 141
 				unset($comments['comments'][$k]);
142 142
 
143
-			}else if($this->depth == 0){
143
+			} else if($this->depth == 0){
144 144
 				$comment->setDepth(0);
145
-			}else{
145
+			} else{
146 146
 				$comment->setDepth($comment->getId());
147 147
 			}
148 148
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 		if($get_by_id)
152 152
 		{
153 153
 			return $comments_by_id;
154
-		}else{
154
+		} else{
155 155
 			return $comments;
156 156
 		}
157 157
 	}
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 				$parent_id[] = $comments_by_id[$index]->getParentId();
178 178
 				$index = $comments_by_id[$index]->getParentId();
179 179
 				$depth_reached++;
180
-			}else{
180
+			} else{
181 181
 				$parent = false;
182 182
 			}
183 183
 		}
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 		if(!empty($criteria) || isset($orderBy) || isset($limit) || isset($offset))
202 202
 		{
203 203
 			return $this->repository->findBy($criteria,$orderBy,$limit,$offset);
204
-		}else{
204
+		} else{
205 205
 			return $this->repository->findAll();
206 206
 		}
207 207
 	}
Please login to merge, or discard this patch.
Manager/Manager.php 3 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: Rafidion Michael
5
- * Date: 03/09/2015
6
- * Time: 12:02
7
- */
3
+     * Created by PhpStorm.
4
+     * User: Rafidion Michael
5
+     * Date: 03/09/2015
6
+     * Time: 12:02
7
+     */
8 8
 
9 9
 namespace Mykees\CommentBundle\Manager;
10 10
 
@@ -12,75 +12,75 @@  discard block
 block discarded – undo
12 12
 abstract class Manager {
13 13
 
14 14
 
15
-	/**
16
-	 * @param $ref
17
-	 * @return string
18
-	 */
19
-	public function getBundleShortName ( $ref ){
20
-		$explode = explode('\\', $this->getClassName($ref));
21
-		return $explode[0].$explode[1];
22
-	}
15
+    /**
16
+     * @param $ref
17
+     * @return string
18
+     */
19
+    public function getBundleShortName ( $ref ){
20
+        $explode = explode('\\', $this->getClassName($ref));
21
+        return $explode[0].$explode[1];
22
+    }
23 23
 
24 24
 
25
-	/**
26
-	 * @param $ref
27
-	 * @return string
28
-	 */
29
-	public function getBundlePath ( $ref ){
30
-		$explode = explode('\\', $this->getClassName($ref));
31
-		return $explode[0].'\\'.$explode[1];
32
-	}
25
+    /**
26
+     * @param $ref
27
+     * @return string
28
+     */
29
+    public function getBundlePath ( $ref ){
30
+        $explode = explode('\\', $this->getClassName($ref));
31
+        return $explode[0].'\\'.$explode[1];
32
+    }
33 33
 
34 34
 
35
-	/**
36
-	 * @param $ref
37
-	 * @param bool $withouSlash
38
-	 * @return string
39
-	 */
40
-	public function getFullBundlePath($ref,$withouSlash = false)
41
-	{
42
-		$explode = explode('\\', $this->getClassName($ref));
43
-		if($withouSlash)
44
-		{
45
-			return $explode[0].$explode[1].':'.$explode[3];
46
-		}else{
47
-			return $explode[0].'\\'.$explode[1].'\\'.$explode[2].'\\'.$explode[3];
48
-		}
49
-	}
35
+    /**
36
+     * @param $ref
37
+     * @param bool $withouSlash
38
+     * @return string
39
+     */
40
+    public function getFullBundlePath($ref,$withouSlash = false)
41
+    {
42
+        $explode = explode('\\', $this->getClassName($ref));
43
+        if($withouSlash)
44
+        {
45
+            return $explode[0].$explode[1].':'.$explode[3];
46
+        }else{
47
+            return $explode[0].'\\'.$explode[1].'\\'.$explode[2].'\\'.$explode[3];
48
+        }
49
+    }
50 50
 
51 51
 
52
-	/**
53
-	 * @param $ref
54
-	 * @return string
55
-	 */
56
-	public function getClassShortName( $ref ) {
57
-		$reflection = new \ReflectionClass( $ref );
58
-		if( $reflection->getParentClass() ) {
59
-			$reflection = $reflection->getParentClass();
60
-		}
61
-		return $reflection->getShortName();
62
-	}
52
+    /**
53
+     * @param $ref
54
+     * @return string
55
+     */
56
+    public function getClassShortName( $ref ) {
57
+        $reflection = new \ReflectionClass( $ref );
58
+        if( $reflection->getParentClass() ) {
59
+            $reflection = $reflection->getParentClass();
60
+        }
61
+        return $reflection->getShortName();
62
+    }
63 63
 
64 64
 
65
-	/**
66
-	 * @param $ref
67
-	 * @return string
68
-	 */
69
-	public function getClassName ( $ref ) {
70
-		$reflection = new \ReflectionClass( $ref );
71
-		return $reflection->getName();
72
-	}
65
+    /**
66
+     * @param $ref
67
+     * @return string
68
+     */
69
+    public function getClassName ( $ref ) {
70
+        $reflection = new \ReflectionClass( $ref );
71
+        return $reflection->getName();
72
+    }
73 73
 
74
-	/**
75
-	 * Retrieve class repository name
76
-	 * @param $comment_class
77
-	 * @return string
78
-	 */
79
-	public function classRepository($comment_class)
80
-	{
81
-		$comment_class_name = $comment_class;
82
-		$explode = explode('\\',$comment_class_name);
74
+    /**
75
+     * Retrieve class repository name
76
+     * @param $comment_class
77
+     * @return string
78
+     */
79
+    public function classRepository($comment_class)
80
+    {
81
+        $comment_class_name = $comment_class;
82
+        $explode = explode('\\',$comment_class_name);
83 83
 
84
-		return $explode[0] . $explode[1] . ":" . $explode[3];
85
-	}
84
+        return $explode[0] . $explode[1] . ":" . $explode[3];
85
+    }
86 86
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 	 * @param $ref
17 17
 	 * @return string
18 18
 	 */
19
-	public function getBundleShortName ( $ref ){
19
+	public function getBundleShortName($ref) {
20 20
 		$explode = explode('\\', $this->getClassName($ref));
21 21
 		return $explode[0].$explode[1];
22 22
 	}
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * @param $ref
27 27
 	 * @return string
28 28
 	 */
29
-	public function getBundlePath ( $ref ){
29
+	public function getBundlePath($ref) {
30 30
 		$explode = explode('\\', $this->getClassName($ref));
31 31
 		return $explode[0].'\\'.$explode[1];
32 32
 	}
@@ -37,13 +37,13 @@  discard block
 block discarded – undo
37 37
 	 * @param bool $withouSlash
38 38
 	 * @return string
39 39
 	 */
40
-	public function getFullBundlePath($ref,$withouSlash = false)
40
+	public function getFullBundlePath($ref, $withouSlash = false)
41 41
 	{
42 42
 		$explode = explode('\\', $this->getClassName($ref));
43
-		if($withouSlash)
43
+		if ($withouSlash)
44 44
 		{
45 45
 			return $explode[0].$explode[1].':'.$explode[3];
46
-		}else{
46
+		}else {
47 47
 			return $explode[0].'\\'.$explode[1].'\\'.$explode[2].'\\'.$explode[3];
48 48
 		}
49 49
 	}
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
 	 * @param $ref
54 54
 	 * @return string
55 55
 	 */
56
-	public function getClassShortName( $ref ) {
57
-		$reflection = new \ReflectionClass( $ref );
58
-		if( $reflection->getParentClass() ) {
56
+	public function getClassShortName($ref) {
57
+		$reflection = new \ReflectionClass($ref);
58
+		if ($reflection->getParentClass()) {
59 59
 			$reflection = $reflection->getParentClass();
60 60
 		}
61 61
 		return $reflection->getShortName();
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	 * @param $ref
67 67
 	 * @return string
68 68
 	 */
69
-	public function getClassName ( $ref ) {
70
-		$reflection = new \ReflectionClass( $ref );
69
+	public function getClassName($ref) {
70
+		$reflection = new \ReflectionClass($ref);
71 71
 		return $reflection->getName();
72 72
 	}
73 73
 
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 	public function classRepository($comment_class)
80 80
 	{
81 81
 		$comment_class_name = $comment_class;
82
-		$explode = explode('\\',$comment_class_name);
82
+		$explode = explode('\\', $comment_class_name);
83 83
 
84
-		return $explode[0] . $explode[1] . ":" . $explode[3];
84
+		return $explode[0].$explode[1].":".$explode[3];
85 85
 	}
86 86
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@
 block discarded – undo
110 110
 		if($locale == 'fr')
111 111
 		{
112 112
 			return "moins d'une minute";
113
-		}else{
113
+		} else{
114 114
 			return 'less than a minute';
115 115
 		}
116 116
 	}
Please login to merge, or discard this patch.
Repository/CommentRepository.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@
 block discarded – undo
12 12
 
13 13
 class CommentRepository extends EntityRepository
14 14
 {
15
-	public function deleteByCommentIds(array $ids)
16
-	{
17
-		return $this->_em->createQueryBuilder()
18
-			->delete("MykeesCommentBundle:Comment",'c')
19
-			->where("c.id IN(:ids)")
20
-			->setParameter('ids', array_values($ids))
21
-			->getQuery()
22
-			->execute()
23
-		;
24
-	}
15
+    public function deleteByCommentIds(array $ids)
16
+    {
17
+        return $this->_em->createQueryBuilder()
18
+            ->delete("MykeesCommentBundle:Comment",'c')
19
+            ->where("c.id IN(:ids)")
20
+            ->setParameter('ids', array_values($ids))
21
+            ->getQuery()
22
+            ->execute()
23
+        ;
24
+    }
25 25
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
 	public function deleteByCommentIds(array $ids)
16 16
 	{
17 17
 		return $this->_em->createQueryBuilder()
18
-			->delete("MykeesCommentBundle:Comment",'c')
18
+			->delete("MykeesCommentBundle:Comment", 'c')
19 19
 			->where("c.id IN(:ids)")
20 20
 			->setParameter('ids', array_values($ids))
21 21
 			->getQuery()
Please login to merge, or discard this patch.
Tests/Controller/CommentsControllerTest.php 2 patches
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: Rafidion Michael
5
- * Date: 23/04/2015
6
- * Time: 02:28
7
- */
3
+     * Created by PhpStorm.
4
+     * User: Rafidion Michael
5
+     * Date: 23/04/2015
6
+     * Time: 02:28
7
+     */
8 8
 
9 9
 namespace Mykees\CommentBundle\Tests\Controller;
10 10
 
@@ -15,32 +15,32 @@  discard block
 block discarded – undo
15 15
 
16 16
     protected $client;
17 17
     protected $container;
18
-	protected $manager;
19
-	protected $query_manager;
18
+    protected $manager;
19
+    protected $query_manager;
20 20
     protected $em;
21 21
     protected $commentClass;
22 22
     protected $request;
23 23
 
24
-   public function setUp()
25
-   {
26
-
24
+    public function setUp()
25
+    {
27 26
 
28
-       $this->client = static::createClient();
29
-       $this->container = $this->client->getContainer();
30
-	   $this->manager = $this->container->get('mykees.comment.manager');
31
-	   $this->query_manager = $this->container->get('mykees.comment.query.manager');
32
-       $this->em = static::$kernel->getContainer()
33
-           ->get('doctrine')
34
-           ->getManager()
35
-       ;
36 27
 
37
-       $fixtures = [
38
-           'Mykees\CommentBundle\DataFixtures\ORM\LoadCommentData',
39
-           'Mvc\BlogBundle\DataFixtures\ORM\LoadPostsData',
40
-       ];
41
-       $this->loadFixtures($fixtures);
42
-       parent::setUp();
43
-   }
28
+        $this->client = static::createClient();
29
+        $this->container = $this->client->getContainer();
30
+        $this->manager = $this->container->get('mykees.comment.manager');
31
+        $this->query_manager = $this->container->get('mykees.comment.query.manager');
32
+        $this->em = static::$kernel->getContainer()
33
+            ->get('doctrine')
34
+            ->getManager()
35
+        ;
36
+
37
+        $fixtures = [
38
+            'Mykees\CommentBundle\DataFixtures\ORM\LoadCommentData',
39
+            'Mvc\BlogBundle\DataFixtures\ORM\LoadPostsData',
40
+        ];
41
+        $this->loadFixtures($fixtures);
42
+        parent::setUp();
43
+    }
44 44
 
45 45
     public function testCountCommentHtmlList()
46 46
     {
@@ -49,150 +49,150 @@  discard block
 block discarded – undo
49 49
         $this->assertEquals(3,$crawler->filter('.comment-list')->count());
50 50
     }
51 51
 
52
-	public function testRemoveAssociateComment()
53
-	{
54
-		$this->client->request('GET', '/admin/delete/5');
55
-		$this->assertEquals(302,$this->client->getResponse()->getStatusCode());
52
+    public function testRemoveAssociateComment()
53
+    {
54
+        $this->client->request('GET', '/admin/delete/5');
55
+        $this->assertEquals(302,$this->client->getResponse()->getStatusCode());
56
+
57
+        $count = count($this->query_manager->findAllComments());
58
+
59
+        $this->assertEquals(4, $count);
60
+    }
61
+
62
+    public function testAddComment()
63
+    {
64
+        $crawler = $this->client->request('GET','/blog/title-1');
65
+        $this->assertEquals('Mvc\BlogBundle\Controller\BlogController::showAction',  $this->client->getRequest()->attributes->get('_controller'));
66
+        $form = $crawler->selectButton('Poster')->form([
67
+            'mykees_comment[username]'=>'Mykees',
68
+            'mykees_comment[email]'=>'[email protected]',
69
+            'mykees_comment[content]'=>'Salut les guedins',
70
+            'mykees_comment[parentId]'=>0,
71
+            'mykees_comment[model]'=>'Post',
72
+            'mykees_comment[modelId]'=>1,
73
+        ]);
74
+
75
+        $this->client->submit($form);
76
+
77
+        $this->assertEquals(302,$this->client->getResponse()->getStatusCode());
78
+
79
+        $count = count($this->query_manager->findAllComments());
80
+
81
+        $this->assertEquals(6, $count);
82
+    }
83
+
84
+    public function testAddCommentWithEmptyName()
85
+    {
86
+        $crawler = $this->client->request('GET','/blog/title-1');
87
+        $this->assertEquals('Mvc\BlogBundle\Controller\BlogController::showAction',  $this->client->getRequest()->attributes->get('_controller'));
88
+        $form = $crawler->selectButton('Poster')->form([
89
+            'mykees_comment[username]'=>'',
90
+            'mykees_comment[email]'=>'[email protected]',
91
+            'mykees_comment[content]'=>'Salut les guedins',
92
+            'mykees_comment[parentId]'=>0,
93
+            'mykees_comment[model]'=>'Post',
94
+            'mykees_comment[modelId]'=>1,
95
+        ]);
96
+
97
+        $this->client->submit($form);
98
+
99
+        $count = count($this->query_manager->findAllComments());
100
+
101
+        $this->assertEquals(5, $count);
102
+    }
103
+
104
+    public function testAddCommentWithWrongEmailFormat()
105
+    {
106
+
107
+        $crawler = $this->client->request('GET','/blog/title-1');
108
+        $form = $crawler->selectButton('Poster')->form([
109
+            'mykees_comment[username]'=>'Mykees',
110
+            'mykees_comment[email]'=>'contact.fr',
111
+            'mykees_comment[content]'=>'Salut les guedins',
112
+            'mykees_comment[parentId]'=>0,
113
+            'mykees_comment[model]'=>'Post',
114
+            'mykees_comment[modelId]'=>1,
115
+        ]);
116
+
117
+        $this->client->submit($form);
118
+
119
+        $count = count($this->query_manager->findAllComments());
120
+
121
+        $this->assertEquals(5, $count);
122
+    }
123
+
124
+
125
+    public function testAddCommmentWithAChild()
126
+    {
127
+        $crawler = $this->client->request('GET','/blog/title-2');
128
+
129
+        $form = $crawler->selectButton('Poster')->form([
130
+            'mykees_comment[username]'=>'Mykees',
131
+            'mykees_comment[email]'=>'[email protected]',
132
+            'mykees_comment[content]'=>'Salut les guedins',
133
+            'mykees_comment[parentId]'=>0,
134
+            'mykees_comment[model]'=>'Post',
135
+            'mykees_comment[modelId]'=>1,
136
+        ]);
137
+        $this->client->submit($form);
138
+
139
+        $this->assertEquals(302,$this->client->getResponse()->getStatusCode());
140
+
141
+        $count = count($this->query_manager->findAllComments());
142
+
143
+        $this->assertEquals(6, $count);
144
+
145
+        $form = $crawler->selectButton('Poster')->form([
146
+            'mykees_comment[username]'=>'Marion',
147
+            'mykees_comment[email]'=>'[email protected]',
148
+            'mykees_comment[content]'=>'Salut les guedins',
149
+            'mykees_comment[parentId]'=>27,
150
+            'mykees_comment[model]'=>'Post',
151
+            'mykees_comment[modelId]'=>1,
152
+        ]);
153
+        $this->client->submit($form);
56 154
 
57
-		$count = count($this->query_manager->findAllComments());
58
-
59
-		$this->assertEquals(4, $count);
60
-	}
155
+        $this->assertEquals(302,$this->client->getResponse()->getStatusCode());
61 156
 
62
-	public function testAddComment()
63
-	{
64
-		$crawler = $this->client->request('GET','/blog/title-1');
65
-		$this->assertEquals('Mvc\BlogBundle\Controller\BlogController::showAction',  $this->client->getRequest()->attributes->get('_controller'));
66
-		$form = $crawler->selectButton('Poster')->form([
67
-			'mykees_comment[username]'=>'Mykees',
68
-			'mykees_comment[email]'=>'[email protected]',
69
-			'mykees_comment[content]'=>'Salut les guedins',
70
-			'mykees_comment[parentId]'=>0,
71
-			'mykees_comment[model]'=>'Post',
72
-			'mykees_comment[modelId]'=>1,
73
-		]);
74
-
75
-		$this->client->submit($form);
76
-
77
-		$this->assertEquals(302,$this->client->getResponse()->getStatusCode());
78
-
79
-		$count = count($this->query_manager->findAllComments());
80
-
81
-		$this->assertEquals(6, $count);
82
-	}
83
-
84
-	public function testAddCommentWithEmptyName()
85
-	{
86
-		$crawler = $this->client->request('GET','/blog/title-1');
87
-		$this->assertEquals('Mvc\BlogBundle\Controller\BlogController::showAction',  $this->client->getRequest()->attributes->get('_controller'));
88
-		$form = $crawler->selectButton('Poster')->form([
89
-			'mykees_comment[username]'=>'',
90
-			'mykees_comment[email]'=>'[email protected]',
91
-			'mykees_comment[content]'=>'Salut les guedins',
92
-			'mykees_comment[parentId]'=>0,
93
-			'mykees_comment[model]'=>'Post',
94
-			'mykees_comment[modelId]'=>1,
95
-		]);
96
-
97
-		$this->client->submit($form);
98
-
99
-		$count = count($this->query_manager->findAllComments());
100
-
101
-		$this->assertEquals(5, $count);
102
-	}
103
-
104
-	public function testAddCommentWithWrongEmailFormat()
105
-	{
106
-
107
-		$crawler = $this->client->request('GET','/blog/title-1');
108
-		$form = $crawler->selectButton('Poster')->form([
109
-			'mykees_comment[username]'=>'Mykees',
110
-			'mykees_comment[email]'=>'contact.fr',
111
-			'mykees_comment[content]'=>'Salut les guedins',
112
-			'mykees_comment[parentId]'=>0,
113
-			'mykees_comment[model]'=>'Post',
114
-			'mykees_comment[modelId]'=>1,
115
-		]);
116
-
117
-		$this->client->submit($form);
118
-
119
-		$count = count($this->query_manager->findAllComments());
120
-
121
-		$this->assertEquals(5, $count);
122
-	}
123
-
124
-
125
-	public function testAddCommmentWithAChild()
126
-	{
127
-		$crawler = $this->client->request('GET','/blog/title-2');
128
-
129
-		$form = $crawler->selectButton('Poster')->form([
130
-			'mykees_comment[username]'=>'Mykees',
131
-			'mykees_comment[email]'=>'[email protected]',
132
-			'mykees_comment[content]'=>'Salut les guedins',
133
-			'mykees_comment[parentId]'=>0,
134
-			'mykees_comment[model]'=>'Post',
135
-			'mykees_comment[modelId]'=>1,
136
-		]);
137
-		$this->client->submit($form);
138
-
139
-		$this->assertEquals(302,$this->client->getResponse()->getStatusCode());
140
-
141
-		$count = count($this->query_manager->findAllComments());
142
-
143
-		$this->assertEquals(6, $count);
144
-
145
-		$form = $crawler->selectButton('Poster')->form([
146
-			'mykees_comment[username]'=>'Marion',
147
-			'mykees_comment[email]'=>'[email protected]',
148
-			'mykees_comment[content]'=>'Salut les guedins',
149
-			'mykees_comment[parentId]'=>27,
150
-			'mykees_comment[model]'=>'Post',
151
-			'mykees_comment[modelId]'=>1,
152
-		]);
153
-		$this->client->submit($form);
154
-
155
-		$this->assertEquals(302,$this->client->getResponse()->getStatusCode());
156
-
157
-		$count = count($this->query_manager->findAllComments());
158
-		$this->assertEquals(7, $count);
159
-
160
-
161
-		$count = count($this->query_manager->findAllComments(['parentId'=>27]));
162
-		$this->assertEquals(1, $count);
163
-	}
164
-
165
-
166
-	public function testPreDeleteComment()
167
-	{
168
-		$crawler = $this->client->request('GET','/blog/title-1');
169
-		$form = $crawler->selectButton('Poster')->form([
170
-			'mykees_comment[username]'=>'Mykees',
171
-			'mykees_comment[email]'=>'[email protected]',
172
-			'mykees_comment[content]'=>'Salut les guedins',
173
-			'mykees_comment[parentId]'=>0,
174
-			'mykees_comment[model]'=>'Post',
175
-			'mykees_comment[modelId]'=>25,
176
-		]);
177
-		$this->client->submit($form);
178
-		$this->assertEquals(302,$this->client->getResponse()->getStatusCode());
179
-		$count = count($this->query_manager->findAllComments());
180
-		$this->assertEquals(6, $count);
181
-
182
-
183
-		$post = $this->em->getRepository('MvcBlogBundle:Post')->find(25);
184
-		$this->em->remove($post);
185
-		$this->em->flush();
186
-
187
-		$count = count($this->query_manager->findAllComments());
188
-		$this->assertEquals(5, $count);
189
-	}
157
+        $count = count($this->query_manager->findAllComments());
158
+        $this->assertEquals(7, $count);
190 159
 
191 160
 
192
-	public function testWithCommentDepthToZero(){
193
-		$crawler = $this->client->request('GET', '/blog/title-1');
194
-		$this->assertEquals(200,$this->client->getResponse()->getStatusCode());
195
-		$this->assertEquals(0,$crawler->filter('.reply')->count());
196
-	}
161
+        $count = count($this->query_manager->findAllComments(['parentId'=>27]));
162
+        $this->assertEquals(1, $count);
163
+    }
164
+
165
+
166
+    public function testPreDeleteComment()
167
+    {
168
+        $crawler = $this->client->request('GET','/blog/title-1');
169
+        $form = $crawler->selectButton('Poster')->form([
170
+            'mykees_comment[username]'=>'Mykees',
171
+            'mykees_comment[email]'=>'[email protected]',
172
+            'mykees_comment[content]'=>'Salut les guedins',
173
+            'mykees_comment[parentId]'=>0,
174
+            'mykees_comment[model]'=>'Post',
175
+            'mykees_comment[modelId]'=>25,
176
+        ]);
177
+        $this->client->submit($form);
178
+        $this->assertEquals(302,$this->client->getResponse()->getStatusCode());
179
+        $count = count($this->query_manager->findAllComments());
180
+        $this->assertEquals(6, $count);
181
+
182
+
183
+        $post = $this->em->getRepository('MvcBlogBundle:Post')->find(25);
184
+        $this->em->remove($post);
185
+        $this->em->flush();
186
+
187
+        $count = count($this->query_manager->findAllComments());
188
+        $this->assertEquals(5, $count);
189
+    }
190
+
191
+
192
+    public function testWithCommentDepthToZero(){
193
+        $crawler = $this->client->request('GET', '/blog/title-1');
194
+        $this->assertEquals(200,$this->client->getResponse()->getStatusCode());
195
+        $this->assertEquals(0,$crawler->filter('.reply')->count());
196
+    }
197 197
 
198 198
 }
199 199
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 use Liip\FunctionalTestBundle\Test\WebTestCase;
13 13
 
14
-class CommentsControllerTest extends WebTestCase{
14
+class CommentsControllerTest extends WebTestCase {
15 15
 
16 16
     protected $client;
17 17
     protected $container;
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
     public function testCountCommentHtmlList()
46 46
     {
47 47
         $crawler = $this->client->request('GET', '/blog/title-1');
48
-        $this->assertEquals(200,$this->client->getResponse()->getStatusCode());
49
-        $this->assertEquals(3,$crawler->filter('.comment-list')->count());
48
+        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
49
+        $this->assertEquals(3, $crawler->filter('.comment-list')->count());
50 50
     }
51 51
 
52 52
 	public function testRemoveAssociateComment()
53 53
 	{
54 54
 		$this->client->request('GET', '/admin/delete/5');
55
-		$this->assertEquals(302,$this->client->getResponse()->getStatusCode());
55
+		$this->assertEquals(302, $this->client->getResponse()->getStatusCode());
56 56
 
57 57
 		$count = count($this->query_manager->findAllComments());
58 58
 
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 
62 62
 	public function testAddComment()
63 63
 	{
64
-		$crawler = $this->client->request('GET','/blog/title-1');
65
-		$this->assertEquals('Mvc\BlogBundle\Controller\BlogController::showAction',  $this->client->getRequest()->attributes->get('_controller'));
64
+		$crawler = $this->client->request('GET', '/blog/title-1');
65
+		$this->assertEquals('Mvc\BlogBundle\Controller\BlogController::showAction', $this->client->getRequest()->attributes->get('_controller'));
66 66
 		$form = $crawler->selectButton('Poster')->form([
67 67
 			'mykees_comment[username]'=>'Mykees',
68 68
 			'mykees_comment[email]'=>'[email protected]',
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 
75 75
 		$this->client->submit($form);
76 76
 
77
-		$this->assertEquals(302,$this->client->getResponse()->getStatusCode());
77
+		$this->assertEquals(302, $this->client->getResponse()->getStatusCode());
78 78
 
79 79
 		$count = count($this->query_manager->findAllComments());
80 80
 
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 
84 84
 	public function testAddCommentWithEmptyName()
85 85
 	{
86
-		$crawler = $this->client->request('GET','/blog/title-1');
87
-		$this->assertEquals('Mvc\BlogBundle\Controller\BlogController::showAction',  $this->client->getRequest()->attributes->get('_controller'));
86
+		$crawler = $this->client->request('GET', '/blog/title-1');
87
+		$this->assertEquals('Mvc\BlogBundle\Controller\BlogController::showAction', $this->client->getRequest()->attributes->get('_controller'));
88 88
 		$form = $crawler->selectButton('Poster')->form([
89 89
 			'mykees_comment[username]'=>'',
90 90
 			'mykees_comment[email]'=>'[email protected]',
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	public function testAddCommentWithWrongEmailFormat()
105 105
 	{
106 106
 
107
-		$crawler = $this->client->request('GET','/blog/title-1');
107
+		$crawler = $this->client->request('GET', '/blog/title-1');
108 108
 		$form = $crawler->selectButton('Poster')->form([
109 109
 			'mykees_comment[username]'=>'Mykees',
110 110
 			'mykees_comment[email]'=>'contact.fr',
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 
125 125
 	public function testAddCommmentWithAChild()
126 126
 	{
127
-		$crawler = $this->client->request('GET','/blog/title-2');
127
+		$crawler = $this->client->request('GET', '/blog/title-2');
128 128
 
129 129
 		$form = $crawler->selectButton('Poster')->form([
130 130
 			'mykees_comment[username]'=>'Mykees',
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		]);
137 137
 		$this->client->submit($form);
138 138
 
139
-		$this->assertEquals(302,$this->client->getResponse()->getStatusCode());
139
+		$this->assertEquals(302, $this->client->getResponse()->getStatusCode());
140 140
 
141 141
 		$count = count($this->query_manager->findAllComments());
142 142
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 		]);
153 153
 		$this->client->submit($form);
154 154
 
155
-		$this->assertEquals(302,$this->client->getResponse()->getStatusCode());
155
+		$this->assertEquals(302, $this->client->getResponse()->getStatusCode());
156 156
 
157 157
 		$count = count($this->query_manager->findAllComments());
158 158
 		$this->assertEquals(7, $count);
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 
166 166
 	public function testPreDeleteComment()
167 167
 	{
168
-		$crawler = $this->client->request('GET','/blog/title-1');
168
+		$crawler = $this->client->request('GET', '/blog/title-1');
169 169
 		$form = $crawler->selectButton('Poster')->form([
170 170
 			'mykees_comment[username]'=>'Mykees',
171 171
 			'mykees_comment[email]'=>'[email protected]',
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 			'mykees_comment[modelId]'=>25,
176 176
 		]);
177 177
 		$this->client->submit($form);
178
-		$this->assertEquals(302,$this->client->getResponse()->getStatusCode());
178
+		$this->assertEquals(302, $this->client->getResponse()->getStatusCode());
179 179
 		$count = count($this->query_manager->findAllComments());
180 180
 		$this->assertEquals(6, $count);
181 181
 
@@ -189,10 +189,10 @@  discard block
 block discarded – undo
189 189
 	}
190 190
 
191 191
 
192
-	public function testWithCommentDepthToZero(){
192
+	public function testWithCommentDepthToZero() {
193 193
 		$crawler = $this->client->request('GET', '/blog/title-1');
194
-		$this->assertEquals(200,$this->client->getResponse()->getStatusCode());
195
-		$this->assertEquals(0,$crawler->filter('.reply')->count());
194
+		$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
195
+		$this->assertEquals(0, $crawler->filter('.reply')->count());
196 196
 	}
197 197
 
198 198
 }
199 199
\ No newline at end of file
Please login to merge, or discard this patch.
Tests/Fixtures/app/AppKernel.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,9 +19,9 @@
 block discarded – undo
19 19
             new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
20 20
 
21 21
             new Mvc\BlogBundle\MvcBlogBundle(),
22
-	        new Mykees\CommentBundle\MykeesCommentBundle(),
23
-	        new Mykees\MediaBundle\MykeesMediaBundle(),
24
-	        new Mykees\TagBundle\MykeesTagBundle(),
22
+            new Mykees\CommentBundle\MykeesCommentBundle(),
23
+            new Mykees\MediaBundle\MykeesMediaBundle(),
24
+            new Mykees\TagBundle\MykeesTagBundle(),
25 25
             new Liip\FunctionalTestBundle\LiipFunctionalTestBundle(),
26 26
         );
27 27
 
Please login to merge, or discard this patch.