TenantProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAvailableTenants() 0 5 1
A findOneByCode() 0 11 2
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
15
namespace SWP\Component\MultiTenancy\Provider;
16
17
use SWP\Component\MultiTenancy\Model\TenantInterface;
18
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface;
19
20
class TenantProvider implements TenantProviderInterface
21
{
22
    private $tenantRepository;
23
24
    private $internalCache = [];
25
26
    public function __construct(TenantRepositoryInterface $tenantRepository)
27
    {
28
        $this->tenantRepository = $tenantRepository;
29
    }
30
31
    public function getAvailableTenants(): array
32
    {
33
        return $this->tenantRepository
34
            ->findAvailableTenants();
35
    }
36
37
    public function findOneByCode(string $tenantCode): ?TenantInterface
38
    {
39
        if (isset($this->internalCache[$tenantCode])) {
40
            return $this->internalCache[$tenantCode];
41
        }
42
43
        $tenant = $this->tenantRepository->findOneByCode($tenantCode);
44
        $this->internalCache[$tenantCode] = $tenant;
45
46
        return $tenant;
47
    }
48
}
49