ObjectPersisterFactory::addObjectPersister()   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 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\SkeletonMapper\Persister;
6
7
use InvalidArgumentException;
8
use function sprintf;
9
10
/**
11
 * Class responsible for retrieving ObjectPersister instances.
12
 */
13
class ObjectPersisterFactory implements ObjectPersisterFactoryInterface
14
{
15
    /** @var ObjectPersisterInterface[] */
16
    private $persisters = [];
17
18 23
    public function addObjectPersister(string $className, ObjectPersisterInterface $objectPersister) : void
19
    {
20 23
        $this->persisters[$className] = $objectPersister;
21 23
    }
22
23 13
    public function getPersister(string $className) : ObjectPersisterInterface
24
    {
25 13
        if (! isset($this->persisters[$className])) {
26
            throw new InvalidArgumentException(sprintf('ObjectPersister with class name %s was not found', $className));
27
        }
28
29 13
        return $this->persisters[$className];
30
    }
31
32
    /**
33
     * @return ObjectPersisterInterface[]
34
     */
35 1
    public function getPersisters() : array
36
    {
37 1
        return $this->persisters;
38
    }
39
}
40