Completed
Pull Request — master (#608)
by Amrouche
05:13 queued 01:46
created

ContextTrait::initContext()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ApiPlatform\Core\Serializer;
13
14
/**
15
 * Creates and manipulates the Serializer context.
16
 *
17
 * @author Kévin Dunglas <[email protected]>
18
 */
19
trait ContextTrait
20
{
21
    /**
22
     * Initializes the context.
23
     *
24
     * @param string $resourceClass
25
     * @param array  $context
26
     *
27
     * @return array
28
     */
29
    private function initContext(string $resourceClass, array $context) : array
30
    {
31
        if (isset($context['api_sub_level'])) {
32
            return $context;
33
        }
34
35
        return array_merge($context, [
36
            'api_sub_level' => true,
37
            'resource_class' => $resourceClass,
38
        ]);
39
    }
40
}
41