RepositoryFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 7
c 3
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getRepository() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasDoctrine\Repository;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\ORM\Repository\RepositoryFactory as RepositoryFactoryInterface;
9
use Doctrine\Persistence\ObjectRepository;
10
11
final class RepositoryFactory implements RepositoryFactoryInterface
12
{
13
    public function __construct(
14
        private readonly EntityRepositoryProviderInterface $repositoryProvider,
15
        private readonly RepositoryFactoryInterface $repositoryFactory
16
    ) {
17
    }
18
19
    /**
20
     * @phpstan-return ObjectRepository<object>
21
     *
22
     * @throws \Exception
23
     */
24
    public function getRepository(EntityManagerInterface $entityManager, $entityName): ObjectRepository
25
    {
26
        if ($this->repositoryProvider->hasRepository($entityName)) {
27
            $options = [
28
                'entity_name' => $entityName,
29
                'entity_manager' => $entityManager,
30
            ];
31
32
            return $this->repositoryProvider->getRepository($entityName, $options);
33
        }
34
35
        return $this->repositoryFactory->getRepository($entityManager, $entityName);
36
    }
37
}
38