ObjectRepositoryFactory::getRepository()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\SkeletonMapper\ObjectRepository;
6
7
use InvalidArgumentException;
8
use function sprintf;
9
10
/**
11
 * Class responsible for retrieving ObjectRepository instances.
12
 */
13
class ObjectRepositoryFactory implements ObjectRepositoryFactoryInterface
14
{
15
    /** @var ObjectRepositoryInterface[] */
16
    private $repositories = [];
17
18 23
    public function addObjectRepository(string $className, ObjectRepositoryInterface $objectRepository) : void
19
    {
20 23
        $this->repositories[$className] = $objectRepository;
21 23
    }
22
23 22
    public function getRepository(string $className) : ObjectRepositoryInterface
24
    {
25 22
        if (! isset($this->repositories[$className])) {
26 1
            throw new InvalidArgumentException(
27 1
                sprintf('ObjectRepository with class name %s was not found', $className)
28
            );
29
        }
30
31 21
        return $this->repositories[$className];
32
    }
33
}
34