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

api-platform / core / 10729306835

05 Sep 2024 10:46PM UTC coverage: 7.655% (-0.01%) from 7.665%
10729306835

push

github

web-flow
Merge pull request #6586 from soyuka/merge-342

Merge 3.4

0 of 54 new or added lines in 12 files covered. (0.0%)

8760 existing lines in 277 files now uncovered.

12505 of 163357 relevant lines covered (7.66%)

22.84 hits per line

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

100.0
/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

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

UNCOV
37
        $context['jsonld_has_context'] = true;
1,259✔
38

UNCOV
39
        if (isset($context['jsonld_embed_context'])) {
1,259✔
UNCOV
40
            $data['@context'] = $contextBuilder->getResourceContext($resourceClass);
3✔
41

UNCOV
42
            return $data;
3✔
43
        }
44

UNCOV
45
        $data['@context'] = $contextBuilder->getResourceContextUri($resourceClass);
1,256✔
46

UNCOV
47
        return $data;
1,256✔
48
    }
49

50
    private function createJsonLdContext(AnonymousContextBuilderInterface $contextBuilder, $object, array &$context): array
51
    {
52
        // We're in a collection, don't add the @context part
UNCOV
53
        if (isset($context['jsonld_has_context'])) {
95✔
UNCOV
54
            return $contextBuilder->getAnonymousResourceContext($object, ($context['output'] ?? []) + ['api_resource' => $context['api_resource'] ?? null, 'has_context' => true]);
80✔
55
        }
56

UNCOV
57
        $context['jsonld_has_context'] = true;
18✔
58

UNCOV
59
        return $contextBuilder->getAnonymousResourceContext($object, ($context['output'] ?? []) + ['api_resource' => $context['api_resource'] ?? null]);
18✔
60
    }
61
}
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