Passed
Pull Request — 2.4 (#2495)
by Antoine
04:02
created

JsonLdContextTrait::createJsonLdContext()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
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\Core\JsonLd\Serializer;
15
16
use ApiPlatform\Core\JsonLd\ContextBuilderInterface;
17
18
/**
19
 * Creates and manipulates the Serializer context.
20
 *
21
 * @author Kévin Dunglas <[email protected]>
22
 *
23
 * @internal
24
 */
25
trait JsonLdContextTrait
26
{
27
    /**
28
     * Updates the given JSON-LD document to add its @context key.
29
     */
30
    private function addJsonLdContext(ContextBuilderInterface $contextBuilder, string $resourceClass, array &$context, array $data = []): array
31
    {
32
        if (isset($context['jsonld_has_context'])) {
33
            return $data;
34
        }
35
36
        $context['jsonld_has_context'] = true;
37
38
        if (isset($context['jsonld_embed_context'])) {
39
            $data['@context'] = $contextBuilder->getResourceContext($resourceClass);
40
41
            return $data;
42
        }
43
44
        $data['@context'] = $contextBuilder->getResourceContextUri($resourceClass);
45
46
        return $data;
47
    }
48
49
    private function createJsonLdContext(ContextBuilderInterface $contextBuilder, $object, array &$context, array $data = []): array
50
    {
51
        if (isset($context['jsonld_has_context'])) {
52
            return $data;
53
        }
54
55
        $context['jsonld_has_context'] = true;
56
57
        return $contextBuilder->getIOResourceContext($object, $context['output']);
0 ignored issues
show
Bug introduced by
The method getIOResourceContext() does not exist on ApiPlatform\Core\JsonLd\ContextBuilderInterface. Did you maybe mean getResourceContext()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        return $contextBuilder->/** @scrutinizer ignore-call */ getIOResourceContext($object, $context['output']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
    }
59
}
60