Completed
Push — feature/serializer-groups ( 7eaea2 )
by Narcotic
63:05
created

ContextFactoryAbstract::setGroups()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dn
5
 * Date: 17.11.17
6
 * Time: 16:52
7
 */
8
9
namespace Graviton\RestBundle\Serializer;
10
11
12
use JMS\Serializer\Context;
13
14
abstract class ContextFactoryAbstract
15
{
16
17
    private $setSerializeNull = true;
18
19
    private $groups = ['Default'];
20
21
    /**
22
     * set SetSerializeNull
23
     *
24
     * @param bool $setSerializeNull setSerializeNull
25
     *
26
     * @return void
27
     */
28
    public function setSetSerializeNull($setSerializeNull)
29
    {
30
        $this->setSerializeNull = $setSerializeNull;
31
    }
32
33
    /**
34
     * set Groups
35
     *
36
     * @param array $groups groups
37
     *
38
     * @return void
39
     */
40
    public function setGroups(array $groups)
41
    {
42
        $this->groups = $groups;
43
    }
44
45
    protected function workOnInstance(Context $context)
46
    {
47
        $context = $context->setSerializeNull($this->setSerializeNull);
48
49
        if (is_array($this->groups) && !empty($this->groups)) {
50
            $context = $context->setGroups($this->groups);
51
        }
52
53
        return $context;
54
    }
55
56
}
57