SubscriptionController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 26 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 4
dl 13
loc 50
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 7 21 3
B detailsAction() 6 25 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 Tahoe\Bundle\MultiTenancyBundle\Controller;
4
5
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Symfony\Component\HttpFoundation\Request;
8
use Tahoe\Bundle\MultiTenancyBundle\Form\Type\SubscriptionType;
9
10
class SubscriptionController extends Controller
11
{
12
    public function indexAction(Request $request)
13
    {
14
        $tenant = $this->get('tahoe.multi_tenancy.tenant_resolver')->getTenant();
15
        if ($this->get('tahoe.multi_tenancy.gateway.recurly')->subscriptionExists($tenant)) {
16
            return $this->redirect($this->generateUrl('tahoe_multitenancy_subscription_details'));
17
        }
18
        $form = $this->createForm(new SubscriptionType(), new \Recurly_BillingInfo());
19
        $form->handleRequest($request);
20
21 View Code Duplication
        if ($form->isValid()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
22
            $this->get('tahoe.multi_tenancy.gateway.recurly')->createSubscription($tenant, $form->getData());
23
24
            $this->get('session')->getFlashBag()->add('success', 'The subscription has been created successfully');
25
26
            return $this->redirect($this->generateUrl('tahoe_multitenancy_subscription'));
27
        }
28
29
        return $this->render('TahoeMultiTenancyBundle:Subscription:index.html.twig', array(
30
            'form' => $form->createView()
31
        ));
32
    }
33
34
    public function detailsAction(Request $request)
35
    {
36
        $tenant = $this->get('tahoe.multi_tenancy.tenant_resolver')->getTenant();
37
        $subscription = $this->get('tahoe.multi_tenancy.gateway.recurly')->getSubscription($tenant);
38
        if (null === $subscription) {
39
            return $this->redirect($this->generateUrl('tahoe_multitenancy_subscription'));
40
        }
41
42
        $billingInfo = $this->get('tahoe.multi_tenancy.gateway.recurly')->getBillingInfo($tenant);
43
44
        $form = $this->createForm(new SubscriptionType(), $billingInfo);
45
        $form->handleRequest($request);
46
47 View Code Duplication
        if ($form->isValid()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
48
            $this->get('tahoe.multi_tenancy.gateway.recurly')->updateBillingInfo($tenant, $form->getData());
49
            $this->get('session')->getFlashBag()->add('success', 'Your billing information has been updated successfully');
50
51
            return $this->redirect($this->generateUrl('tahoe_multitenancy_subscription'));
52
        }
53
54
        return $this->render('TahoeMultiTenancyBundle:Subscription:index.html.twig', array(
55
            'form' => $form->createView(),
56
            'update' => true
57
        ));
58
    }
59
}