Completed
Push — master ( e61615...870684 )
by Pavel
04:58
created

JmsContextFactory::configureContext()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 3
eloc 7
nc 3
nop 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
    public static function serialization(array $context = null)
17
    {
18
        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
    private static function configureContext(Context $jmsContext, array $context = null)
27
    {
28
        $jmsContext->setSerializeNull(true);
29
30
        if (null === $context) {
31
            return $jmsContext;
32
        }
33
34
        if (array_key_exists('groups', $context)) {
35
            $jmsContext->setGroups($context['groups']);
36
        }
37
38
        return $jmsContext;
39
    }
40
}
41