RepositoryFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

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