Passed
Push — master ( c1150e...84b7ab )
by Michael
02:30
created

ResourceIdentifierObject::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Component\JsonApi\Document;
5
6
use Mikemirten\Component\JsonApi\Document\Behaviour\MetadataAwareInterface;
7
use Mikemirten\Component\JsonApi\Document\Behaviour\MetadataContainer;
8
use Mikemirten\Component\JsonApi\Document\Behaviour\ResourceBehaviour;
9
10
/**
11
 * Resource Identifier Object
12
 *
13
 * @see http://jsonapi.org/format/#document-resource-identifier-objects
14
 *
15
 * @package Mikemirten\Component\JsonApi\Document
16
 */
17
class ResourceIdentifierObject implements MetadataAwareInterface
18
{
19
    use ResourceBehaviour;
20
    use MetadataContainer;
21
22
    /**
23
     * ResourceObject constructor.
24
     *
25
     * @param string $id
26
     * @param string $type
27
     * @param array  $metadata
28
     */
29
    public function __construct(string $id, string $type, array $metadata = [])
30
    {
31
        $this->id       = $id;
32
        $this->type     = $type;
33
        $this->metadata = $metadata;
34
    }
35
36
    /**
37
     * Cast to an array
38
     *
39
     * @return array
40
     */
41
    public function toArray(): array
42
    {
43
        $data = $this->resourceToArray();
44
45
        if ($this->hasMetadata()) {
46
            $data['meta'] = $this->getMetadata();
47
        }
48
49
        return $data;
50
    }
51
}