Code Duplication    Length = 21-22 lines in 3 locations

src/PlaygroundGame/Controller/Frontend/PostVoteController.php 3 locations

@@ 697-718 (lines=22) @@
694
        $response = $this->getResponse();
695
        $post = $this->getGameService()->getPostvotePostMapper()->findById($postId);
696
697
        if (!$this->zfcUserAuthentication()->hasIdentity()) {
698
            $response->setContent(\Zend\Json\Json::encode(array(
699
                'success' => 0
700
            )));
701
        } else {
702
            if ($request->isPost()) {
703
                if ($this->getGameService()->addComment(
704
                    $this->user,
705
                    $this->getRequest()->getServer('REMOTE_ADDR'),
706
                    $post,
707
                    $this->params()->fromPost('comment')
708
                )) {
709
                    $response->setContent(\Zend\Json\Json::encode(array(
710
                        'success' => 1
711
                    )));
712
                } else {
713
                    $response->setContent(\Zend\Json\Json::encode(array(
714
                        'success' => 0
715
                    )));
716
                }
717
            }
718
        }
719
720
        //ajax call ?
721
        if ($this->getRequest()->isXmlHttpRequest()) {
@@ 636-657 (lines=22) @@
633
            return $response;
634
        }
635
636
        if (!$this->zfcUserAuthentication()->hasIdentity()) {
637
            $response->setContent(\Zend\Json\Json::encode(array(
638
                'success' => 0
639
            )));
640
        } else {
641
            if ($request->isPost()) {
642
                $post = $this->getGameService()->getPostvotePostMapper()->findById($postId);
643
                if ($this->getGameService()->addVote(
644
                    $this->user,
645
                    $this->getRequest()->getServer('REMOTE_ADDR'),
646
                    $post
647
                )) {
648
                    $response->setContent(\Zend\Json\Json::encode(array(
649
                        'success' => 1
650
                    )));
651
                } else {
652
                    $response->setContent(\Zend\Json\Json::encode(array(
653
                        'success' => 0
654
                    )));
655
                }
656
            }
657
        }
658
659
        return $response;
660
    }
@@ 753-773 (lines=21) @@
750
            return $response;
751
        }
752
753
        if (!$this->zfcUserAuthentication()->hasIdentity()) {
754
            $response->setContent(\Zend\Json\Json::encode(array(
755
                'success' => 0
756
            )));
757
        } else {
758
            if ($request->isPost()) {
759
                if ($this->getGameService()->removeComment(
760
                    $this->user,
761
                    $this->getRequest()->getServer('REMOTE_ADDR'),
762
                    $commentId
763
                )) {
764
                    $response->setContent(\Zend\Json\Json::encode(array(
765
                        'success' => 1
766
                    )));
767
                } else {
768
                    $response->setContent(\Zend\Json\Json::encode(array(
769
                        'success' => 0
770
                    )));
771
                }
772
            }
773
        }
774
775
        return $response;
776
    }