BasicObjectHydrator::__construct()   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 1
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\Hydrator;
6
7
use Doctrine\SkeletonMapper\ObjectManagerInterface;
8
use InvalidArgumentException;
9
use function get_class;
10
use function sprintf;
11
12
/**
13
 * Basic object hydrator that delegates hydration
14
 * to a method on the object that is being hydrated
15
 * or uses a dynamic hydration algorithm.
16
 */
17
class BasicObjectHydrator extends ObjectHydrator
18
{
19
    /** @var ObjectManagerInterface */
20
    protected $objectManager;
21
22 23
    public function __construct(ObjectManagerInterface $objectManager)
23
    {
24 23
        $this->objectManager = $objectManager;
25 23
    }
26
27
    /**
28
     * @param object  $object
29
     * @param mixed[] $data
30
     */
31 18
    public function hydrate($object, array $data) : void
32
    {
33 18
        if (! $object instanceof HydratableInterface) {
34
            throw new InvalidArgumentException(sprintf(
35
                'Class %s does not implement %s.',
36
                get_class($object),
37
                HydratableInterface::class
38
            ));
39
        }
40
41 18
        $object->hydrate($data, $this->objectManager);
42 18
    }
43
}
44