TenantRepository::findOneByCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function findOneBySubdomainAndDomain($subdomain, $domain)
29
    {
30
        return $this
31
            ->createQueryBuilder('t')
32
            ->select('t', 'o', 'oc')
33
            ->leftJoin('t.organization', 'o')
34
            ->leftJoin('t.outputChannel', 'oc')
35
            ->where('t.subdomain = :subdomain')
36
            ->andWhere('t.domainName = :domainName')
37
            ->setParameters([
38
                'subdomain' => $subdomain,
39
                'domainName' => $domain,
40
            ])
41
            ->getQuery()
42
            ->getOneOrNullResult();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 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...
49
    {
50
        return $this
51
            ->createQueryBuilder('t')
52
            ->select('t', 'o', 'oc')
53
            ->leftJoin('t.organization', 'o')
54
            ->leftJoin('t.outputChannel', 'oc')
55
            ->where('t.domainName = :domainName')
56
            ->andWhere('t.subdomain IS NULL')
57
            ->setParameter('domainName', $domain)
58
            ->getQuery()
59
            ->getOneOrNullResult();
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 View Code Duplication
    public function findOneByCode($code)
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...
66
    {
67
        return $this
68
            ->createQueryBuilder('t')
69
            ->select('t', 'o')
70
            ->leftJoin('t.organization', 'o')
71
            ->leftJoin('t.outputChannel', 'oc')
72
            ->where('t.code = :code')
73
            ->setParameter('code', $code)
74
            ->getQuery()
75
            ->getOneOrNullResult();
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function findAvailableTenants()
82
    {
83
        return $this
84
            ->createQueryBuilder('t')
85
            ->select('t', 'o')
86
            ->leftJoin('t.organization', 'o')
87
            ->leftJoin('t.outputChannel', 'oc')
88
            ->getQuery()
89
            ->getArrayResult();
90
    }
91
}
92