Completed
Push — master ( 6718d9...b5055a )
by Rafał
14:45
created

TenantRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 41.54 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 27
loc 65
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findOneBySubdomainAndDomain() 15 15 1
A findOneByDomain() 12 12 1
A findOneByCode() 0 11 1
A findAvailableTenants() 0 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 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
15
namespace SWP\Bundle\MultiTenancyBundle\Doctrine\ORM;
16
17
use SWP\Bundle\StorageBundle\Doctrine\ORM\EntityRepository;
18
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface;
19
20
/**
21
 * Repository interface for tenants.
22
 */
23
class TenantRepository extends EntityRepository implements TenantRepositoryInterface
0 ignored issues
show
Bug introduced by
There is one abstract method findOneBySubdomain in this class; you could implement it, or declare this class as abstract.
Loading history...
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 View Code Duplication
    public function findOneBySubdomainAndDomain($subdomain, $domain)
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...
29
    {
30
        return $this
31
            ->createQueryBuilder('t')
32
            ->select('t', 'o')
33
            ->leftJoin('t.organization', 'o')
34
            ->where('t.subdomain = :subdomain')
35
            ->andWhere('t.domainName = :domainName')
36
            ->setParameters([
37
                'subdomain' => $subdomain,
38
                'domainName' => $domain,
39
            ])
40
            ->getQuery()
41
            ->getOneOrNullResult();
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 View Code Duplication
    public function findOneByDomain($domain)
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...
48
    {
49
        return $this
50
            ->createQueryBuilder('t')
51
            ->select('t', 'o')
52
            ->leftJoin('t.organization', 'o')
53
            ->where('t.domainName = :domainName')
54
            ->andWhere('t.subdomain IS NULL')
55
            ->setParameter('domainName', $domain)
56
            ->getQuery()
57
            ->getOneOrNullResult();
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function findOneByCode($code)
64
    {
65
        return $this
66
            ->createQueryBuilder('t')
67
            ->select('t', 'o')
68
            ->leftJoin('t.organization', 'o')
69
            ->where('t.code = :code')
70
            ->setParameter('code', $code)
71
            ->getQuery()
72
            ->getOneOrNullResult();
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function findAvailableTenants()
79
    {
80
        return $this
81
            ->createQueryBuilder('t')
82
            ->select('t', 'o')
83
            ->leftJoin('t.organization', 'o')
84
            ->getQuery()
85
            ->getArrayResult();
86
    }
87
}
88