Completed
Pull Request — master (#2743)
by Jeroen
16:52 queued 10:35
created

VotingController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 13.41 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 9
dl 11
loc 82
ccs 0
cts 39
cp 0
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A upVoteAction() 0 6 1
A downVoteAction() 0 6 1
A facebookLikeAction() 0 6 1
A facebookSendAction() 0 6 1
A linkedInShareAction() 0 6 1
A dispatch() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Kunstmaan\VotingBundle\Controller;
4
5
use Kunstmaan\VotingBundle\Event\Events;
6
use Kunstmaan\VotingBundle\Event\Facebook\FacebookLikeEvent;
7
use Kunstmaan\VotingBundle\Event\Facebook\FacebookSendEvent;
8
use Kunstmaan\VotingBundle\Event\LinkedIn\LinkedInShareEvent;
9
use Kunstmaan\VotingBundle\Event\UpDown\DownVoteEvent;
10
use Kunstmaan\VotingBundle\Event\UpDown\UpVoteEvent;
11
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
12
use Symfony\Component\Routing\Annotation\Route;
13
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
14
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
15
use Symfony\Component\HttpFoundation\Request;
16
17
class VotingController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
18
{
19
    /**
20
     * @Route("/voting-upvote", name="voting_upvote")
21
     * @Template("@KunstmaanVoting/UpDown/voted.html.twig")
22
     *
23
     * @param \Symfony\Component\HttpFoundation\Request $request
24
     */
25
    public function upVoteAction(Request $request)
26
    {
27
        $reference = $request->get('reference');
28
        $value = $request->get('value');
29
        $this->dispatch(new UpVoteEvent($request, $reference, $value), Events::VOTE_UP);
30
    }
31
32
    /**
33
     * @Route("/voting-downvote", name="voting_downvote")
34
     * @Template("@KunstmaanVoting/UpDown/voted.html.twig")
35
     *
36
     * @param \Symfony\Component\HttpFoundation\Request $request
37
     */
38
    public function downVoteAction(Request $request)
39
    {
40
        $reference = $request->get('reference');
41
        $value = $request->get('value');
42
        $this->dispatch(new DownVoteEvent($request, $reference, $value), Events::VOTE_DOWN);
43
    }
44
45
    /**
46
     * @Route("/voting-facebooklike", name="voting_facebooklike")
47
     *
48
     * @param \Symfony\Component\HttpFoundation\Request $request
49
     */
50
    public function facebookLikeAction(Request $request)
51
    {
52
        $response = $request->get('response');
53
        $value = $request->get('value');
54
        $this->dispatch(new FacebookLikeEvent($request, $response, $value), Events::FACEBOOK_LIKE);
55
    }
56
57
    /**
58
     * @Route("/voting-facebooksend", name="voting_facebooksend")
59
     *
60
     * @param \Symfony\Component\HttpFoundation\Request $request
61
     */
62
    public function facebookSendAction(Request $request)
63
    {
64
        $response = $request->get('response');
65
        $value = $request->get('value');
66
        $this->dispatch(new FacebookSendEvent($request, $response, $value), Events::FACEBOOK_SEND);
67
    }
68
69
    /**
70
     * @Route("/voting-linkedinshare", name="voting_linkedinshare")
71
     *
72
     * @param \Symfony\Component\HttpFoundation\Request $request
73
     */
74
    public function linkedInShareAction(Request $request)
75
    {
76
        $reference = $request->get('reference');
77
        $value = $request->get('value');
78
        $this->dispatch(new LinkedInShareEvent($request, $reference, $value), Events::LINKEDIN_SHARE);
79
    }
80
81
    /**
82
     * @param object $event
83
     * @param string $eventName
84
     *
85
     * @return object
86
     */
87 View Code Duplication
    private function dispatch($event, string $eventName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
    {
89
        $eventDispatcher = $this->container->get('event_dispatcher');
90
        if (class_exists(LegacyEventDispatcherProxy::class)) {
91
            $eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
92
93
            return $eventDispatcher->dispatch($event, $eventName);
94
        }
95
96
        return $eventDispatcher->dispatch($eventName, $event);
97
    }
98
}
99