Completed
Push — master ( e93435...670f0c )
by Pavel
09:43
created

JmsContextFactory::deserialization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Adaptors\JmsSerializer;
4
5
use JMS\Serializer\Context;
6
use JMS\Serializer\DeserializationContext;
7
use JMS\Serializer\SerializationContext;
8
9
final class JmsContextFactory
10
{
11
    /**
12
     * @param null|array $context
13
     *
14
     * @return SerializationContext
15
     */
16 6
    public static function serialization(array $context = null)
17
    {
18 6
        return self::configureContext(SerializationContext::create(), $context);
19
    }
20
21
    public static function deserialization($context)
22
    {
23
        return self::configureContext(DeserializationContext::create(), $context);
24
    }
25
26 6
    private static function configureContext(Context $jmsContext, array $context = null)
27
    {
28 6
        $jmsContext->setSerializeNull(true);
29
30 6
        if (null === $context) {
31
            return $jmsContext;
32
        }
33
34 6
        if (array_key_exists('groups', $context)) {
35
            $jmsContext->setGroups($context['groups']);
36
        }
37
38 6
        if (array_key_exists('object_to_populate', $context)) {
39
            $jmsContext->setAttribute('target', $context['object_to_populate']);
40
        }
41
42 6
        return $jmsContext;
43
    }
44
}
45