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

api-platform / core / 7196499749

13 Dec 2023 02:17PM UTC coverage: 37.359% (+1.4%) from 36.003%
7196499749

push

github

web-flow
ci: conflict sebastian/comparator (#6032)

* ci: conflict sebastian/comparator

* for lowest

10295 of 27557 relevant lines covered (37.36%)

28.14 hits per line

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

92.86
/src/JsonLd/Serializer/JsonLdContextTrait.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\JsonLd\Serializer;
15

16
use ApiPlatform\JsonLd\AnonymousContextBuilderInterface;
17
use ApiPlatform\JsonLd\ContextBuilderInterface;
18
use ApiPlatform\Metadata\Error;
19

20
/**
21
 * Creates and manipulates the Serializer context.
22
 *
23
 * @author Kévin Dunglas <dunglas@gmail.com>
24
 *
25
 * @internal
26
 */
27
trait JsonLdContextTrait
28
{
29
    /**
30
     * Updates the given JSON-LD document to add its @context key.
31
     */
32
    private function addJsonLdContext(ContextBuilderInterface $contextBuilder, string $resourceClass, array &$context, array $data = []): array
33
    {
34
        if (isset($context['jsonld_has_context'])) {
64✔
35
            return $data;
8✔
36
        }
37

38
        $context['jsonld_has_context'] = true;
64✔
39

40
        if (isset($context['jsonld_embed_context'])) {
64✔
41
            $data['@context'] = $contextBuilder->getResourceContext($resourceClass);
4✔
42

43
            return $data;
4✔
44
        }
45

46
        if (($operation = $context['operation'] ?? null) && ($operation->getExtraProperties()['rfc_7807_compliant_errors'] ?? false) && $operation instanceof Error) {
60✔
47
            return $data;
×
48
        }
49

50
        $data['@context'] = $contextBuilder->getResourceContextUri($resourceClass);
60✔
51

52
        return $data;
60✔
53
    }
54

55
    private function createJsonLdContext(AnonymousContextBuilderInterface $contextBuilder, $object, array &$context): array
56
    {
57
        // We're in a collection, don't add the @context part
58
        if (isset($context['jsonld_has_context'])) {
16✔
59
            return $contextBuilder->getAnonymousResourceContext($object, ($context['output'] ?? []) + ['api_resource' => $context['api_resource'] ?? null, 'has_context' => true]);
4✔
60
        }
61

62
        $context['jsonld_has_context'] = true;
12✔
63

64
        return $contextBuilder->getAnonymousResourceContext($object, ($context['output'] ?? []) + ['api_resource' => $context['api_resource'] ?? null]);
12✔
65
    }
66
}
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

© 2026 Coveralls, Inc