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

ContextTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A initContext() 0 11 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