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

api-platform / core / 10943429050

19 Sep 2024 02:48PM UTC coverage: 7.647% (-0.03%) from 7.675%
10943429050

push

github

web-flow
feat: api-platform/json-hal component (#6621)

* feat: add hal support for laravel

* feat: quick review

* fix: typo & cs-fixer

* fix: typo in composer.json

* fix: cs-fixer & phpstan

* fix: forgot about hal item normalizer, therefore there's no more createbook nor updatebook test as Hal is a readonly format

0 of 94 new or added lines in 2 files covered. (0.0%)

9082 existing lines in 291 files now uncovered.

12629 of 165144 relevant lines covered (7.65%)

22.89 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,266✔
UNCOV
34
            return $data;
573✔
35
        }
36

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

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

UNCOV
42
            return $data;
3✔
43
        }
44

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

UNCOV
47
        return $data;
1,260✔
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