ManageSubscriptionsController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 35.56 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A manageAction() 16 16 1
A deleteAction() 0 18 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
/**
4
 * @author Rafał Muszyński <[email protected]>
5
 * @copyright 2013 Sourcefabric o.p.s.
6
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
7
 */
8
9
namespace Newscoop\PaywallBundle\Controller;
10
11
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
12
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\HttpFoundation\Response;
15
use Newscoop\PaywallBundle\Entity\Subscription;
16
use Newscoop\PaywallBundle\Criteria\SubscriptionCriteria;
17
use Newscoop\PaywallBundle\Permissions;
18
19
class ManageSubscriptionsController extends BaseController
20
{
21
    /**
22
     * @Route("/admin/paywall_plugin/manage", options={"expose"=true})
23
     * @Template()
24
     */
25 View Code Duplication
    public function manageAction(Request $request)
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...
26
    {
27
        $this->hasPermission(Permissions::SUBSCRIPTIONS_VIEW);
28
        $subscription = new Subscription();
29
        $form = $this->createForm('subscriptionconf', $subscription);
30
        $em = $this->getDoctrine()->getManager();
31
        $criteria = new SubscriptionCriteria();
32
        $subscriptions = $em->getRepository('Newscoop\PaywallBundle\Entity\Subscription')
33
            ->getListByCriteria($criteria, true)
34
            ->getResult();
35
36
        return array(
37
            'subscriptions' => $subscriptions,
38
            'form' => $form->createView(),
39
        );
40
    }
41
42
    /**
43
     * @Route("/admin/paywall_plugin/manage/delete/{id}")
44
     */
45
    public function deleteAction(Request $request, $id)
46
    {
47
        $this->hasPermission(Permissions::SUBSCRIPTIONS_MANAGE);
48
        if ($request->isMethod('POST')) {
49
            $em = $this->getDoctrine()->getManager();
50
            $subscription = $em->getRepository('Newscoop\PaywallBundle\Entity\Subscription')
51
                ->findOneBy(array('id' => $id));
52
53
            foreach ($subscription->getSpecification() as $value) {
54
                $value->setIsActive(false);
55
            }
56
57
            $subscription->setIsActive(false);
58
            $em->flush();
59
60
            return new Response(json_encode(array('status' => true)));
61
        }
62
    }
63
}
64