TenantProvider::findOneByCode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
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