BasicObjectHydrator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A hydrate() 0 11 2
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