ObjectRepositoryFactory::addObjectRepository()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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