ObjectRepositoryFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRepository() 0 9 2
A addObjectRepository() 0 3 1
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