Completed
Pull Request — master (#15)
by Jonathan
05:36
created

BasicObjectHydrator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 11 2
A __construct() 0 3 1
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
     *
30
     * @param mixed[] $data
31
     */
32 18
    public function hydrate($object, array $data) : void
33
    {
34 18
        if (! $object instanceof HydratableInterface) {
35
            throw new InvalidArgumentException(sprintf(
36
                'Class %s does not implement %s.',
37
                get_class($object),
38
                HydratableInterface::class
39
            ));
40
        }
41
42 18
        $object->hydrate($data, $this->objectManager);
43 18
    }
44
}
45