Completed
Pull Request — master (#1)
by Rafał
09:02
created

TenantContextSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 25 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 3
dl 17
loc 68
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 6 1
A it_is_initializable() 0 4 1
A it_implements_tenant_context_interface() 0 4 1
A it_should_set_tenant() 8 8 1
A it_should_resolve_tenant_from_request() 0 15 1
A it_should_get_default_tenant_when_no_host_found() 0 13 1
A it_should_get_tenant() 9 9 1

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
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace spec\SWP\MultiTenancyBundle\Context;
15
16
use PhpSpec\ObjectBehavior;
17
use SWP\Component\MultiTenancy\Model\TenantInterface;
18
use SWP\Component\MultiTenancy\Resolver\TenantResolverInterface;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\HttpFoundation\RequestStack;
21
22
class TenantContextSpec extends ObjectBehavior
23
{
24
    public function let(
25
        TenantResolverInterface $tenantResolver,
26
        RequestStack $requestStack
27
    ) {
28
        $this->beConstructedWith($tenantResolver, $requestStack);
29
    }
30
31
    public function it_is_initializable()
32
    {
33
        $this->shouldHaveType('SWP\MultiTenancyBundle\Context\TenantContext');
34
    }
35
36
    public function it_implements_tenant_context_interface()
37
    {
38
        $this->shouldImplement('SWP\Component\MultiTenancy\Context\TenantContextInterface');
39
    }
40
41 View Code Duplication
    public function it_should_set_tenant(TenantInterface $tenant)
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...
42
    {
43
        $tenant->getId()->willReturn(1);
44
        $tenant->getSubdomain()->willReturn('example1');
45
        $tenant->getName()->willReturn('example1');
46
47
        $this->setTenant($tenant)->shouldBeNull();
48
    }
49
50
    public function it_should_resolve_tenant_from_request(
51
        $requestStack,
52
        Request $request,
53
        $tenantResolver,
54
        TenantInterface $tenant
55
    ) {
56
        $requestStack->getCurrentRequest()->willReturn($request);
57
        $request->getHost()->shouldBeCalled()->willReturn('example.com');
58
        $tenant->getId()->willReturn(1);
59
        $tenant->getSubdomain()->willReturn('default');
60
        $tenant->getName()->willReturn('Default');
61
        $tenantResolver->resolve('example.com')->willReturn($tenant);
62
63
        $this->getTenant()->shouldReturn($tenant);
64
    }
65
66
    public function it_should_get_default_tenant_when_no_host_found(
67
        $tenantResolver,
68
        $requestStack,
69
        TenantInterface $tenant
70
    ) {
71
        $requestStack->getCurrentRequest()->willReturn(null);
72
        $tenant->getId()->willReturn(1);
73
        $tenant->getSubdomain()->willReturn('default');
74
        $tenant->getName()->willReturn('Default');
75
        $tenantResolver->resolve(null)->willReturn($tenant);
76
77
        $this->getTenant()->shouldReturn($tenant);
78
    }
79
80 View Code Duplication
    public function it_should_get_tenant(TenantInterface $tenant)
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...
81
    {
82
        $tenant->getId()->willReturn(1);
83
        $tenant->getSubdomain()->willReturn('example1');
84
        $tenant->getName()->willReturn('example1');
85
86
        $this->setTenant($tenant)->shouldBeNull();
87
        $this->getTenant()->shouldEqual($tenant);
88
    }
89
}
90