IncludedExtension::supports()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Component\JsonApi\Hydrator\Extension;
5
6
use Mikemirten\Component\JsonApi\Document\Behaviour\IncludedResourcesAwareInterface;
7
use Mikemirten\Component\JsonApi\Hydrator\DocumentHydrator;
8
9
/**
10
 * "included" extension
11
 *
12
 * @see http://jsonapi.org/format/#document-compound-documents
13
 *
14
 * @package Mikemirten\Component\JsonApi\Hydrator\Extension
15
 */
16 View Code Duplication
class IncludedExtension implements ExtensionInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 2
    public function hydrate($object, $source, DocumentHydrator $hydrator)
22
    {
23 2
        if (! $object instanceof IncludedResourcesAwareInterface) {
24
            throw new InvalidDocumentException(sprintf(
25
                'Given instance of "%s" does not implements "%s"',
26
                get_class($object),
27
                IncludedResourcesAwareInterface::class
28
            ));
29
        }
30
31 2
        foreach ($source as $item)
32
        {
33 1
            $resource = $hydrator->hydrateResource($item);
34
35 1
            $object->addIncludedResource($resource);
36
        }
37 2
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 1
    public function supports(): array
43
    {
44 1
        return ['included'];
45
    }
46
}