• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 16050929464

03 Jul 2025 12:51PM UTC coverage: 22.065% (+0.2%) from 21.821%
16050929464

push

github

soyuka
chore: todo improvement

11516 of 52192 relevant lines covered (22.06%)

22.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/src/Serializer/OperationContextTrait.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
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
declare(strict_types=1);
13

14
namespace ApiPlatform\Serializer;
15

16
use ApiPlatform\Metadata\ApiProperty;
17

18
/**
19
 * @internal
20
 */
21
trait OperationContextTrait
22
{
23
    /**
24
     * This context is created when working on a relation context or items of a collection. It cleans the previously given
25
     * context as the operation changes.
26
     */
27
    protected function createOperationContext(array $context, ?string $resourceClass = null, ?ApiProperty $propertyMetadata = null): array
28
    {
29
        if (isset($context['operation']) && !isset($context['root_operation'])) {
342✔
30
            $context['root_operation'] = $context['operation'];
312✔
31
        }
32

33
        if (isset($context['operation_name']) || isset($context['graphql_operation_name'])) {
342✔
34
            $context['root_operation_name'] = $context['operation_name'] ?? $context['graphql_operation_name'];
322✔
35
        }
36

37
        unset($context['iri'], $context['uri_variables'], $context['item_uri_template'], $context['force_resource_class']);
342✔
38

39
        // At some point we should merge the jsonld context here, there's a TODO to simplify this somewhere else
40
        if ($propertyMetadata) {
342✔
41
            $context['output'] ??= [];
182✔
42
            $context['output']['gen_id'] = $propertyMetadata->getGenId() ?? true;
182✔
43
        }
44

45
        if (!$resourceClass) {
342✔
46
            return $context;
×
47
        }
48

49
        if (($operation = $context['operation'] ?? null) && method_exists($operation, 'getItemUriTemplate')) {
342✔
50
            $context['item_uri_template'] = $operation->getItemUriTemplate();
264✔
51
        }
52

53
        unset($context['operation'], $context['operation_name']);
342✔
54
        $context['resource_class'] = $resourceClass;
342✔
55

56
        return $context;
342✔
57
    }
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc