Completed
Pull Request — master (#1)
by Rafał
22:28
created

TenantResolverSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 55.81 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 24
loc 43
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_tenant_resolver_interface() 0 4 1
A it_resolves_tenant_from_subdomain() 12 12 1
A it_resolves_tenant_from_default_root_host() 12 12 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 Component.
5
 *
6
 * Copyright 2015 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 2015 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace spec\SWP\Component\MultiTenancy\Resolver;
15
16
use PhpSpec\ObjectBehavior;
17
use SWP\Component\MultiTenancy\Model\TenantInterface;
18
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface;
19
20
class TenantResolverSpec extends ObjectBehavior
21
{
22
    public function let(TenantRepositoryInterface $tenantRepository)
23
    {
24
        $this->beConstructedWith('domain.com', $tenantRepository);
25
    }
26
27
    public function it_is_initializable()
28
    {
29
        $this->shouldHaveType('SWP\Component\MultiTenancy\Resolver\TenantResolver');
30
    }
31
32
    public function it_implements_tenant_resolver_interface()
33
    {
34
        $this->shouldImplement('SWP\Component\MultiTenancy\Resolver\TenantResolverInterface');
35
    }
36
37 View Code Duplication
    public function it_resolves_tenant_from_subdomain($tenantRepository, 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...
38
    {
39
        $tenant->getId()->willReturn(1);
40
        $tenant->getSubdomain()->willReturn('example1');
41
        $tenant->getName()->willReturn('example1');
42
43
        $tenantRepository->findBySubdomain('example1')
44
            ->shouldBeCalled()
45
            ->willReturn($tenant);
46
47
        $this->resolve('example1.domain.com')->shouldReturn($tenant);
48
    }
49
50 View Code Duplication
    public function it_resolves_tenant_from_default_root_host($tenantRepository, 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...
51
    {
52
        $tenant->getId()->willReturn(1);
53
        $tenant->getSubdomain()->willReturn('default');
54
        $tenant->getName()->willReturn('default');
55
56
        $tenantRepository->findBySubdomain('default')
57
            ->shouldBeCalled()
58
            ->willReturn($tenant);
59
60
        $this->resolve('domain.com')->shouldReturn($tenant);
61
    }
62
}
63