Hydrator::validateRawData()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 14
rs 9.4285
cc 3
eloc 8
nc 4
nop 1
1
<?php
2
3
namespace GFG\DTOContext\Factory;
4
5
use GFG\DTOContext\Context;
6
7
class Hydrator implements HydratorInterface
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12
    public function hydrate(
13
        Context\ContextInterface $context,
14
        array $rawData
15
    ) {
16
        if (!isset($rawData['info'])) {
17
            $rawData['info'] = [];
18
        }
19
20
        $this->validateRawData($rawData);
21
22
        $context->setName($rawData['name'])
23
            ->setFullInfo($rawData['info'])
24
            ->setHash($rawData['hash']);
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function validateRawData(array $rawData)
31
    {
32
        if (!isset($rawData['info'])) {
33
            $rawData['info'] = [];
34
        }
35
        if (count(array_diff(
36
            ['name', 'data_wrapper', 'info', 'hash', 'data'],
37
            array_keys($rawData)
38
        ))) {
39
            throw new \InvalidArgumentException(
40
                'Invalid data to hydrate context: ' . json_encode($rawData)
41
            );
42
        }
43
    }
44
}
45