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

JmsContextFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 53.33%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 36
ccs 8
cts 15
cp 0.5333
rs 10
c 0
b 0
f 0

3 Methods

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