AbstractRelationship   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 25
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 14 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
}