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

TenantRepository::initializeTenant()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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