AbstractRelationship::toArray()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.7998
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 3
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Component\JsonApi\Document;
5
6
use Mikemirten\Component\JsonApi\Document\Behaviour\LinksAwareInterface;
7
use Mikemirten\Component\JsonApi\Document\Behaviour\LinksContainer;
8
use Mikemirten\Component\JsonApi\Document\Behaviour\MetadataAwareInterface;
9
use Mikemirten\Component\JsonApi\Document\Behaviour\MetadataContainer;
10
11
/**
12
 * Abstract relationship
13
 *
14
 * @see http://jsonapi.org/format/#document-resource-object-relationships
15
 *
16
 * Represents base relationship structure
17
 * Supposed to be extended by case based relationships
18
 *
19
 * @package Mikemirten\Component\JsonApi\Document
20
 */
21
abstract class AbstractRelationship implements MetadataAwareInterface, LinksAwareInterface
22
{
23
    use MetadataContainer;
24
    use LinksContainer;
25
26
    /**
27
     * Cast to an array
28
     *
29
     * @return array
30
     */
31 8
    public function toArray(): array
32
    {
33 8
        $data = [];
34
35 8
        if ($this->hasMetadata()) {
36 3
            $data['meta'] = $this->getMetadata();
37
        }
38
39 8
        if ($this->hasLinks()) {
40 3
            $data['links'] = $this->linksToArray();
41
        }
42
43 8
        return $data;
44
    }
45
}