Completed
Push — master ( e4ee84...996ef7 )
by Julito
48:07 queued 18:14
created

SidebarController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 103
Duplicated Lines 43.69 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 45
loc 103
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A userPanelAction() 15 15 2
A userProfileAction() 15 15 2
A socialPanelAction() 15 15 2
A searchFormAction() 0 4 1
A getDispatcher() 0 4 1
A menuKnpAction() 0 19 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
 * SidebarController.php
4
 * avanzu-admin
5
 * Date: 23.02.14
6
 */
7
8
namespace Chamilo\ThemeBundle\Controller;
9
10
use Chamilo\ThemeBundle\Event\ShowUserEvent;
11
use Chamilo\ThemeBundle\Event\SidebarMenuEvent;
12
use Chamilo\ThemeBundle\Event\SidebarMenuKnpEvent;
13
use Chamilo\ThemeBundle\Event\ThemeEvents;
14
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
18
/**
19
 * Class SidebarController
20
 * @package Chamilo\ThemeBundle\Controller
21
 */
22
class SidebarController extends Controller
23
{
24
    /**
25
     * Avatar user panel
26
     * @return Response
27
     */
28 View Code Duplication
    public function userPanelAction()
29
    {
30
        if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_SIDEBAR_USER)) {
31
            return new Response();
32
        }
33
34
        $userEvent = $this->getDispatcher()->dispatch(ThemeEvents::THEME_SIDEBAR_USER, new ShowUserEvent());
35
36
        return $this->render(
37
            'ChamiloThemeBundle:Sidebar:user-panel.html.twig',
38
            array(
39
                'user' => $userEvent->getUser()
40
            )
41
        );
42
    }
43
44
     /**
45
     * User inbox, profile links
46
     * @return Response
47
     */
48 View Code Duplication
    public function userProfileAction()
49
    {
50
        if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_SIDEBAR_USER)) {
51
            return new Response();
52
        }
53
54
        $userEvent = $this->getDispatcher()->dispatch(ThemeEvents::THEME_SIDEBAR_USER, new ShowUserEvent());
55
56
        return $this->render(
57
            'ChamiloThemeBundle:Sidebar:user-profile.html.twig',
58
            array(
59
                'user' => $userEvent->getUser()
60
            )
61
        );
62
    }
63
64
    /**
65
     * User social network section
66
     * @return Response
67
     */
68 View Code Duplication
    public function socialPanelAction()
69
    {
70
        if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_SIDEBAR_USER)) {
71
            return new Response();
72
        }
73
74
        $userEvent = $this->getDispatcher()->dispatch(ThemeEvents::THEME_SIDEBAR_USER, new ShowUserEvent());
75
76
        return $this->render(
77
            'ChamiloThemeBundle:Sidebar:social-panel.html.twig',
78
            array(
79
                'user' => $userEvent->getUser()
80
            )
81
        );
82
    }
83
84
    /**
85
     * Search bar
86
     * @return Response
87
     */
88
    public function searchFormAction()
89
    {
90
        return $this->render('ChamiloThemeBundle:Sidebar:search-form.html.twig', array());
91
    }
92
93
    /**
94
     * @return EventDispatcher
95
     */
96
    protected function getDispatcher()
97
    {
98
        return $this->get('event_dispatcher');
99
    }
100
101
    /**
102
     * @param Request $request
103
     * @return Response
104
     */
105
    public function menuKnpAction(Request $request)
106
    {
107
        if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_SIDEBAR_SETUP_MENU_KNP)) {
108
            return new Response();
109
        }
110
111
        /** @var SidebarMenuKnpEvent $event */
112
        $event = $this->getDispatcher()->dispatch(
113
            ThemeEvents::THEME_SIDEBAR_SETUP_MENU_KNP,
114
            new SidebarMenuKnpEvent($request)
115
        );
116
117
        return $this->render(
118
            'ChamiloThemeBundle:Sidebar:menu_knp.html.twig',
119
            array(
120
                'menu' => $event->getMenu()
121
            )
122
        );
123
    }
124
}
125