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

JmsContextFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serialization() 0 4 1
A deserialization() 0 4 1
A configureContext() 0 14 3
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