Completed
Push — master ( 4284f6...258d83 )
by
unknown
09:47
created

CallController   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 185
Duplicated Lines 18.38 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 6
dl 34
loc 185
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A activityAction() 0 6 1
A createAction() 0 19 1
A updateAction() 0 6 1
A indexAction() 0 6 1
A viewAction() 0 6 1
A callsAction() 0 6 1
A baseCallsAction() 0 6 1
A infoAction() 0 8 1
A update() 23 23 3
A getTargetEntity() 11 11 3

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 OroCRM\Bundle\CallBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
8
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\Request;
10
11
use Oro\Bundle\SecurityBundle\Annotation\Acl;
12
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor;
13
14
use OroCRM\Bundle\CallBundle\Entity\Call;
15
16
class CallController extends Controller
17
{
18
    /**
19
     * This action is used to render the list of calls associated with the given entity
20
     * on the view page of this entity
21
     *
22
     * @Route("/activity/view/{entityClass}/{entityId}", name="orocrm_call_activity_view")
23
     * @AclAncestor("orocrm_call_view")
24
     * @Template
25
     */
26
    public function activityAction($entityClass, $entityId)
27
    {
28
        return array(
29
            'entity' => $this->get('oro_entity.routing_helper')->getEntity($entityClass, $entityId)
30
        );
31
    }
32
33
    /**
34
     * @Route("/create", name="orocrm_call_create")
35
     * @Template("OroCRMCallBundle:Call:update.html.twig")
36
     * @Acl(
37
     *      id="orocrm_call_create",
38
     *      type="entity",
39
     *      permission="CREATE",
40
     *      class="OroCRMCallBundle:Call"
41
     * )
42
     */
43
    public function createAction()
44
    {
45
        $entity = new Call();
46
47
        $callStatus = $this->getDoctrine()
0 ignored issues
show
Bug introduced by
The method findOneByName() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findOneBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
48
            ->getRepository('OroCRMCallBundle:CallStatus')
49
            ->findOneByName('completed');
50
        $entity->setCallStatus($callStatus);
51
52
        $callDirection = $this->getDoctrine()
0 ignored issues
show
Bug introduced by
The method findOneByName() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findOneBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
53
            ->getRepository('OroCRMCallBundle:CallDirection')
54
            ->findOneByName('outgoing');
55
        $entity->setDirection($callDirection);
56
57
        $formAction = $this->get('oro_entity.routing_helper')
58
            ->generateUrlByRequest('orocrm_call_create', $this->getRequest());
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Bundle\Framework...ontroller::getRequest() has been deprecated with message: since version 2.4, to be removed in 3.0. Ask Symfony to inject the Request object into your controller method instead by type hinting it in the method's signature.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
59
60
        return $this->update($entity, $formAction);
61
    }
62
63
    /**
64
     * @Route("/update/{id}", name="orocrm_call_update", requirements={"id"="\d+"})
65
     * @Template
66
     * @Acl(
67
     *      id="orocrm_call_update",
68
     *      type="entity",
69
     *      permission="EDIT",
70
     *      class="OroCRMCallBundle:Call"
71
     * )
72
     */
73
    public function updateAction(Call $entity)
74
    {
75
        $formAction = $this->get('router')->generate('orocrm_call_update', ['id' => $entity->getId()]);
76
77
        return $this->update($entity, $formAction);
78
    }
79
80
    /**
81
     * @Route(name="orocrm_call_index")
82
     * @Template
83
     * @Acl(
84
     *      id="orocrm_call_view",
85
     *      type="entity",
86
     *      permission="VIEW",
87
     *      class="OroCRMCallBundle:Call"
88
     * )
89
     */
90
    public function indexAction()
91
    {
92
        return array(
93
            'entity_class' => $this->container->getParameter('orocrm_call.call.entity.class')
94
        );
95
    }
96
97
    /**
98
     * @Route("/view/{id}", name="orocrm_call_view")
99
     * @Template
100
     */
101
    public function viewAction(Call $entity)
102
    {
103
        return [
104
            'entity' => $entity,
105
        ];
106
    }
107
108
    /**
109
     * @Route("/widget", name="orocrm_call_widget_calls")
110
     * @Template
111
     * @AclAncestor("orocrm_call_view")
112
     *
113
     * @param Request $request
114
     * @return array
115
     */
116
    public function callsAction(Request $request)
117
    {
118
        return array(
119
            'datagridParameters' => $request->query->all()
120
        );
121
    }
122
123
    /**
124
     * @Route("/base-widget", name="orocrm_call_base_widget_calls")
125
     * @Template
126
     * @AclAncestor("orocrm_call_view")
127
     */
128
    public function baseCallsAction(Request $request)
129
    {
130
        return array(
131
            'datagridParameters' => $request->query->all()
132
        );
133
    }
134
135
    /**
136
     * @Route(
137
     *      "/widget/info/{id}/{renderContexts}",
138
     *      name="orocrm_call_widget_info",
139
     *      requirements={"id"="\d+", "renderContexts"="\d+"},
140
     *      defaults={"renderContexts"=true}
141
     * )
142
     * @Template("OroCRMCallBundle:Call/widget:info.html.twig")
143
     * @AclAncestor("orocrm_call_view")
144
     */
145
    public function infoAction(Call $entity, $renderContexts)
146
    {
147
        return [
148
            'entity'         => $entity,
149
            'target'         => $this->getTargetEntity(),
150
            'renderContexts' => (bool)$renderContexts
151
        ];
152
    }
153
154
    /**
155
     * @param Call   $entity
156
     * @param string $formAction
157
     *
158
     * @return array
159
     */
160 View Code Duplication
    protected function update(Call $entity, $formAction)
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...
161
    {
162
        $saved = false;
163
164
        if ($this->get('orocrm_call.call.form.handler')->process($entity)) {
165
            if (!$this->getRequest()->get('_widgetContainer')) {
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Bundle\Framework...ontroller::getRequest() has been deprecated with message: since version 2.4, to be removed in 3.0. Ask Symfony to inject the Request object into your controller method instead by type hinting it in the method's signature.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
166
                $this->get('session')->getFlashBag()->add(
167
                    'success',
168
                    $this->get('translator')->trans('orocrm.call.controller.call.saved.message')
169
                );
170
171
                return $this->get('oro_ui.router')->redirect($entity);
172
            }
173
            $saved = true;
174
        }
175
176
        return array(
177
            'entity'     => $entity,
178
            'saved'      => $saved,
179
            'form'       => $this->get('orocrm_call.call.form.handler')->getForm()->createView(),
180
            'formAction' => $formAction
181
        );
182
    }
183
184
    /**
185
     * Get target entity
186
     *
187
     * @return object|null
188
     */
189 View Code Duplication
    protected function getTargetEntity()
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...
190
    {
191
        $entityRoutingHelper = $this->get('oro_entity.routing_helper');
192
        $targetEntityClass   = $entityRoutingHelper->getEntityClassName($this->getRequest(), 'targetActivityClass');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Bundle\Framework...ontroller::getRequest() has been deprecated with message: since version 2.4, to be removed in 3.0. Ask Symfony to inject the Request object into your controller method instead by type hinting it in the method's signature.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
193
        $targetEntityId      = $entityRoutingHelper->getEntityId($this->getRequest(), 'targetActivityId');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Bundle\Framework...ontroller::getRequest() has been deprecated with message: since version 2.4, to be removed in 3.0. Ask Symfony to inject the Request object into your controller method instead by type hinting it in the method's signature.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
194
        if (!$targetEntityClass || !$targetEntityId) {
195
            return null;
196
        }
197
198
        return $entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
199
    }
200
}
201