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

api-platform / core / 6250499992

20 Sep 2023 03:04PM UTC coverage: 36.863% (-0.2%) from 37.089%
6250499992

push

github

web-flow
fix: errors without compatibility flag (#5841)

24 of 24 new or added lines in 8 files covered. (100.0%)

10081 of 27347 relevant lines covered (36.86%)

13.36 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'])) {
48✔
35
            return $data;
6✔
36
        }
37

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

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

43
            return $data;
3✔
44
        }
45

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

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

52
        return $data;
45✔
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'])) {
12✔
59
            return $contextBuilder->getAnonymousResourceContext($object, ($context['output'] ?? []) + ['api_resource' => $context['api_resource'] ?? null, 'has_context' => true]);
3✔
60
        }
61

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

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