TenantRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 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
    public function __construct(ManagerRegistry $registry, private string $tenantClass)
14
    {
15
        parent::__construct($registry, $tenantClass);
16
    }
17
18
    public function findById($id): ?TenantInterface
19
    {
20
        return $this->findOneBy(['id' => $id]);
21
    }
22
23
    public function findByClientKey(string $clientKey): ?TenantInterface
24
    {
25
        return $this->findOneBy(['clientKey' => $clientKey]);
26
    }
27
28
    public function save(TenantInterface $tenant): void
29
    {
30
        $this->getEntityManager()->persist($tenant);
31
        $this->getEntityManager()->flush();
32
    }
33
34
    public function initializeTenant(): TenantInterface
35
    {
36
        return new $this->tenantClass();
37
    }
38
}
39