Passed
Push — master ( 1b26fd...643675 )
by Matthieu
04:35
created

TenantRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findByClientKey() 0 3 1
A initializeTenant() 0 3 1
A save() 0 4 1
A findById() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AtlassianConnectBundle\Repository;
6
7
use AtlassianConnectBundle\Entity\TenantInterface;
8
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
9
use Doctrine\Persistence\ManagerRegistry;
10
11
final class TenantRepository extends ServiceEntityRepository implements TenantRepositoryInterface
12
{
13
    private string $tenantClass;
14
15
    public function __construct(ManagerRegistry $registry, string $tenantClass)
16
    {
17
        $this->tenantClass = $tenantClass;
18
        parent::__construct($registry, $tenantClass);
19
    }
20
21
    public function findById($id): ?TenantInterface
22
    {
23
        return $this->findOneBy(['id' => $id]);
24
    }
25
26
    public function findByClientKey(string $clientKey): ?TenantInterface
27
    {
28
        return $this->findOneBy(['clientKey' => $clientKey]);
29
    }
30
31
    public function save(TenantInterface $tenant): void
32
    {
33
        $this->getEntityManager()->persist($tenant);
34
        $this->getEntityManager()->flush();
35
    }
36
37
    public function initializeTenant(): TenantInterface
38
    {
39
        return new $this->tenantClass();
40
    }
41
}
42