Completed
Push — master ( 205102...ec6600 )
by Rafidison
02:47
created
Controller/AdminCommentsController.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,10 +15,10 @@  discard block
 block discarded – undo
15 15
 	public function deleteWithChildrenAction($model, $model_id, $comment_id, Request $request)
16 16
 	{
17 17
 		$manager = $this->get('mykees.comment.query.manager');
18
-		$comments = $manager->findCommentsByModelAndId($model, $model_id,true);
18
+		$comments = $manager->findCommentsByModelAndId($model, $model_id, true);
19 19
 		$children_ids = $manager->getChildren($comments[$comment_id]);
20 20
 
21
-		array_push($children_ids,$comment_id);
21
+		array_push($children_ids, $comment_id);
22 22
 
23 23
 		$manager->deleteByCommentIds($children_ids);
24 24
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	public function deleteAction($id, Request $request)
30 30
 	{
31 31
 		$class = $this->container->getParameter('mykees_comment.comment.class');
32
-		$explose_class = explode('\\',$class);
32
+		$explose_class = explode('\\', $class);
33 33
 		$repository = $explose_class[0].$explose_class[1].':'.$explose_class[3];
34 34
 		$comment = $this->gEm()->getRepository($repository)->find($id);
35 35
 
Please login to merge, or discard this patch.
Controller/CommentsController.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -32,30 +32,30 @@  discard block
 block discarded – undo
32 32
 
33 33
 		$comment_class_name = $this->container->getParameter('mykees_comment.comment.class');
34 34
 		$comment_class = new $comment_class_name();
35
-		$form = $this->createForm($this->get('mykees.comment.form'),$comment_class);
35
+		$form = $this->createForm($this->get('mykees.comment.form'), $comment_class);
36 36
 
37
-		if('POST' == $request->getMethod()) {
37
+		if ('POST' == $request->getMethod()) {
38 38
 
39 39
 			if ($form->handleRequest($request)->isValid()) {
40 40
 
41
-				if($request->isXmlHttpRequest()) {
42
-					return $this->ajaxInfo($params,$request,$comment_class);
41
+				if ($request->isXmlHttpRequest()) {
42
+					return $this->ajaxInfo($params, $request, $comment_class);
43 43
 				}
44 44
 
45 45
 				$this->postInfo($params, $request, $comment_class, $params['session']);
46 46
 
47
-			}else{
47
+			}else {
48 48
 
49
-				if($request->isXmlHttpRequest()) {
49
+				if ($request->isXmlHttpRequest()) {
50 50
 					return $this->returnAjaxErrors($form);
51
-				}else{
51
+				}else {
52 52
 					$this->error($request, $params['session']);
53 53
 				}
54 54
 			}
55 55
 
56 56
 		}
57 57
 
58
-		return $this->redirect($request->headers->get('referer') . '#comments_area');
58
+		return $this->redirect($request->headers->get('referer').'#comments_area');
59 59
 	}
60 60
 
61 61
 	/**
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 	 * @param $comment_class
65 65
 	 * @return Response
66 66
 	 */
67
-	private function ajaxInfo($params,$request,$comment_class)
67
+	private function ajaxInfo($params, $request, $comment_class)
68 68
 	{
69 69
 
70 70
 		$comment = $this->postInfo($params, $request, $comment_class, $params['session']);
71 71
 		$comment_depth = $this->container->getParameter('comment.depth');
72 72
 
73 73
 		// Si la profondeur du commentaire parent est inférieure ou égale à la profondeur définis
74
-		if($request->request->get('depth') < $comment_depth && $comment_depth >= 1)
74
+		if ($request->request->get('depth') < $comment_depth && $comment_depth >= 1)
75 75
 		{
76
-			$comment->setDepthReached($request->request->get('depth') + 1);//On incremente la profondeur max
76
+			$comment->setDepthReached($request->request->get('depth') + 1); //On incremente la profondeur max
77 77
 			$comment->setDepth($comment->getId()); //la profondeur de réponse est égale a l'id
78 78
 			$max_depth = false;
79
-		}else{
80
-			$comment->setDepthReached($request->request->get('depth'));//On à atteint la profondeur max
81
-			$comment->setDepth($comment->getParentId());//la profondeur de réponse est éagle au commentaire parent
79
+		}else {
80
+			$comment->setDepthReached($request->request->get('depth')); //On à atteint la profondeur max
81
+			$comment->setDepth($comment->getParentId()); //la profondeur de réponse est éagle au commentaire parent
82 82
 			$max_depth = true;
83 83
 		}
84 84
 
85
-		$template = $this->renderResponse($comment,$request,$max_depth);
85
+		$template = $this->renderResponse($comment, $request, $max_depth);
86 86
 		$json = json_encode([
87 87
 			'template'=>$template,
88 88
 			"parent_id"=>$comment->getParentId(),
@@ -101,20 +101,20 @@  discard block
 block discarded – undo
101 101
 	 * @param $max_depth
102 102
 	 * @return string
103 103
 	 */
104
-	private function renderResponse($comment,$request,$max_depth)
104
+	private function renderResponse($comment, $request, $max_depth)
105 105
 	{
106
-		if($comment->getParentId() > 0)
106
+		if ($comment->getParentId() > 0)
107 107
 		{
108
-			if( ($request->request->get('response_type') === "true" && $max_depth === true) ||
108
+			if (($request->request->get('response_type') === "true" && $max_depth === true) ||
109 109
 				($request->request->get('response_type') === "false" && $max_depth === true) ||
110 110
 				($request->request->get('response_type') === "true" && $max_depth === false)
111
-			){
112
-				return $this->renderView('MykeesCommentBundle:Comments:unwrap_replies.html.twig',['comment'=>$comment,'recent_reply'=>true]);
113
-			}else{
114
-				return $this->renderView('MykeesCommentBundle:Comments:replies.html.twig',['comment'=>$comment,'recent_reply'=>true]);
111
+			) {
112
+				return $this->renderView('MykeesCommentBundle:Comments:unwrap_replies.html.twig', ['comment'=>$comment, 'recent_reply'=>true]);
113
+			}else {
114
+				return $this->renderView('MykeesCommentBundle:Comments:replies.html.twig', ['comment'=>$comment, 'recent_reply'=>true]);
115 115
 			}
116
-		}else{
117
-			return $this->renderView('MykeesCommentBundle:Comments:comment.html.twig',['comment'=>$comment,'recent_reply'=>true]);
116
+		}else {
117
+			return $this->renderView('MykeesCommentBundle:Comments:comment.html.twig', ['comment'=>$comment, 'recent_reply'=>true]);
118 118
 		}
119 119
 	}
120 120
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	private function postInfo($params, $request, $comment, $session)
131 131
 	{
132 132
 		$this->userInfo($request, $comment);
133
-		$this->commentInfo($params,$comment,$request,$params['ref_id']);
133
+		$this->commentInfo($params, $comment, $request, $params['ref_id']);
134 134
 
135 135
 		$this->save($comment);
136 136
 		$this->messageFlash($session);
@@ -158,14 +158,14 @@  discard block
 block discarded – undo
158 158
 	 * @param $ref_id
159 159
 	 * @return mixed
160 160
 	 */
161
-	private function commentInfo($params,$comment,$request,$ref_id)
161
+	private function commentInfo($params, $comment, $request, $ref_id)
162 162
 	{
163 163
 		$comment->setIp($request->getClientIp());
164 164
 		$comment->setModel($params['ref']);
165 165
 		$comment->setModelId($ref_id);
166 166
 		//Spam ?
167 167
 		$akismet = $this->container->hasParameter('akismet') ? $this->container->getParameter('akismet') : null;
168
-		$params['manager']->isSpam($comment,$request,$akismet) ? $comment->setSpam(1) : $comment->setSpam(0);
168
+		$params['manager']->isSpam($comment, $request, $akismet) ? $comment->setSpam(1) : $comment->setSpam(0);
169 169
 
170 170
 		return $comment;
171 171
 	}
@@ -178,15 +178,15 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	private function userInfo($request, $comment)
180 180
 	{
181
-		$is_join = method_exists($comment,'getUser') ? true : false;
181
+		$is_join = method_exists($comment, 'getUser') ? true : false;
182 182
 
183
-		if($this->getUser() !== null)
183
+		if ($this->getUser() !== null)
184 184
 		{
185
-			if($this->getUser()->getUsername() != $comment->getUsername() || $this->getUser()->getEmail() != $comment->getEmail())
185
+			if ($this->getUser()->getUsername() != $comment->getUsername() || $this->getUser()->getEmail() != $comment->getEmail())
186 186
 			{
187
-				return $this->redirect($request->headers->get('referer') . '#comments_area');
187
+				return $this->redirect($request->headers->get('referer').'#comments_area');
188 188
 			}
189
-			if($is_join)
189
+			if ($is_join)
190 190
 			{
191 191
 				$comment->setUser($this->getUser());
192 192
 			}
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
 	private function messageFlash($session)
204 204
 	{
205 205
 		$html = $session->has('success_message') ? $session->get('success_message') : "<strong>Merci!</strong> Votre message à bien été posté.";
206
-		if($this->get('session')->getFlashBag()->has('comment_success'))
206
+		if ($this->get('session')->getFlashBag()->has('comment_success'))
207 207
 		{
208
-			$this->get('session')->getFlashBag()->set('comment_success','');
208
+			$this->get('session')->getFlashBag()->set('comment_success', '');
209 209
 		}
210
-		$this->get('session')->getFlashBag()->add('comment_success',$html);
210
+		$this->get('session')->getFlashBag()->add('comment_success', $html);
211 211
 
212 212
 		return true;
213 213
 	}
@@ -219,9 +219,9 @@  discard block
 block discarded – undo
219 219
 	private function error($request, $session)
220 220
 	{
221 221
 		$requestData = $request->request->get('mykees_comment');
222
-		if(!empty($requestData))
222
+		if (!empty($requestData))
223 223
 		{
224
-			$session->set('form_comment_data',$request->request->get('mykees_comment'));
224
+			$session->set('form_comment_data', $request->request->get('mykees_comment'));
225 225
 		}
226 226
 	}
227 227
 
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	 */
251 251
 	private function returnAjaxErrors($form)
252 252
 	{
253
-		$json = json_encode(['error'=>'error','error_fields'=>$this->getErrorsAsArray($form)]);
253
+		$json = json_encode(['error'=>'error', 'error_fields'=>$this->getErrorsAsArray($form)]);
254 254
 		return new Response($json);
255 255
 	}
256 256
 }
Please login to merge, or discard this patch.
DataFixtures/ORM/LoadCommentData.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
14 14
 use Symfony\Component\DependencyInjection\ContainerInterface;
15 15
 
16
-class LoadCommentData implements FixtureInterface,ContainerAwareInterface{
16
+class LoadCommentData implements FixtureInterface, ContainerAwareInterface{
17 17
 
18 18
 	public $container;
19 19
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	{
39 39
 		$comment_class = $this->container->getParameter('mykees_comment.comment.class');
40 40
 
41
-		for($i=1; $i<=5 ;$i++)
41
+		for ($i = 1; $i <= 5; $i++)
42 42
 		{
43 43
 			$comment = new $comment_class();
44 44
 			$comment->setUsername('admin'.$i);
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
 			$comment->setContent('contenu n-'.$i);
47 47
 			$comment->setCreatedAt(new \DateTime());
48 48
 			$comment->setModel('Post');
49
-			if($i <= 3)
49
+			if ($i <= 3)
50 50
 			{
51 51
 				$comment->setModelId(1);
52
-			}else{
52
+			}else {
53 53
 				$comment->setModelId($i);
54 54
 			}
55 55
 			$comment->setParentId(0);
Please login to merge, or discard this patch.
Entity/Comment.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@
 block discarded – undo
314 314
 	 */
315 315
 	public function setChildren(Comment $children)
316 316
 	{
317
-		array_unshift($this->children,$children);
317
+		array_unshift($this->children, $children);
318 318
 	}
319 319
 
320 320
 	/**
Please login to merge, or discard this patch.
Form/Type/CommentFormEditType.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -24,20 +24,20 @@
 block discarded – undo
24 24
 			->add('username')
25 25
 			->add('email')
26 26
 			->add('content')
27
-			->add('model',"text",[
27
+			->add('model', "text", [
28 28
 				'required'=>false
29 29
 			])
30
-			->add('modelId',"text",[
30
+			->add('modelId', "text", [
31 31
 				'required'=>false
32 32
 			])
33
-			->add('parentId',"text",[
33
+			->add('parentId', "text", [
34 34
 				'required'=>false
35 35
 			])
36
-			->add('spam',"text",[
36
+			->add('spam', "text", [
37 37
 				'required'=>false,
38 38
 				'data'=>0
39 39
 			])
40
-			->add('ip',"text",[
40
+			->add('ip', "text", [
41 41
 				'required'=>false
42 42
 			])
43 43
 		;
Please login to merge, or discard this patch.
Form/Type/CommentFormType.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	public function __construct(TokenStorageInterface $tokenStorage)
20 20
 	{
21 21
 		$this->tokenStorage = $tokenStorage->getToken();
22
-		$this->user = method_exists($this->tokenStorage,'getUser') ? $this->tokenStorage->getUser() : array();
22
+		$this->user = method_exists($this->tokenStorage, 'getUser') ? $this->tokenStorage->getUser() : array();
23 23
 	}
24 24
     /**
25 25
      * @param FormBuilderInterface $builder
@@ -27,34 +27,34 @@  discard block
 block discarded – undo
27 27
      */
28 28
     public function buildForm(FormBuilderInterface $builder, array $options)
29 29
     {
30
-	    if(empty($this->user) || $this->user == 'anon.')
30
+	    if (empty($this->user) || $this->user == 'anon.')
31 31
 	    {
32 32
 		    $builder
33
-			    ->add('username','text',[
33
+			    ->add('username', 'text', [
34 34
 				    'label'=> $this->username
35 35
 			    ])
36
-			    ->add('email','text',[
36
+			    ->add('email', 'text', [
37 37
 				    'label'=> $this->email
38 38
 			    ])
39
-			    ->add('content','textarea',[
39
+			    ->add('content', 'textarea', [
40 40
 				    'label'=> $this->content
41 41
 			    ])
42
-			    ->add('parentId','hidden',['data'=>0])
43
-			    ->add('model','hidden')
44
-			    ->add('modelId','hidden')
42
+			    ->add('parentId', 'hidden', ['data'=>0])
43
+			    ->add('model', 'hidden')
44
+			    ->add('modelId', 'hidden')
45 45
 		    ;
46
-	    }else{
46
+	    }else {
47 47
 		    $builder
48
-			    ->add('username','hidden',[
48
+			    ->add('username', 'hidden', [
49 49
 				    'data'=>$this->user->getUsername()
50 50
 			    ])
51
-			    ->add('email','hidden',[
51
+			    ->add('email', 'hidden', [
52 52
 				    'data'=>$this->user->getEmail()
53 53
 			    ])
54 54
 			    ->add('content')
55
-			    ->add('parentId','hidden',['data'=>0])
56
-			    ->add('model','hidden')
57
-			    ->add('modelId','hidden')
55
+			    ->add('parentId', 'hidden', ['data'=>0])
56
+			    ->add('model', 'hidden')
57
+			    ->add('modelId', 'hidden')
58 58
 		    ;
59 59
 	    }
60 60
     }
Please login to merge, or discard this patch.
Listener/CommentListener.php 1 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 1 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 1 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.