Relationship   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 65%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 70
ccs 13
cts 20
cp 0.65
rs 10
c 2
b 1
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getData() 0 4 1
A setData() 0 6 1
A toArray() 0 18 4
1
<?php
2
3
/*
4
 * This file is part of JSON-API.
5
 *
6
 * (c) Toby Zerner <[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
namespace Tobscure\JsonApi;
13
14
class Relationship
15
{
16
    use LinksTrait;
17
    use MetaTrait;
18
19
    /**
20
     * The data object.
21
     *
22
     * @var \Tobscure\JsonApi\ElementInterface|null
23
     */
24
    protected $data;
25
26
    /**
27
     * Create a new relationship.
28
     *
29
     * @param \Tobscure\JsonApi\ElementInterface|null $data
30
     */
31 21
    public function __construct(ElementInterface $data = null)
32
    {
33 21
        $this->data = $data;
34 21
    }
35
36
    /**
37
     * Get the data object.
38
     *
39
     * @return \Tobscure\JsonApi\ElementInterface|null
40
     */
41 12
    public function getData()
42
    {
43 12
        return $this->data;
44
    }
45
46
    /**
47
     * Set the data object.
48
     *
49
     * @param \Tobscure\JsonApi\ElementInterface|null $data
50
     *
51
     * @return $this
52
     */
53
    public function setData($data)
54
    {
55
        $this->data = $data;
56
57
        return $this;
58
    }
59
60
    /**
61
     * Map everything to an array.
62
     *
63
     * @return array
64
     */
65 12
    public function toArray()
66
    {
67 12
        $array = [];
68
69 12
        if (! empty($this->data)) {
70 12
            $array['data'] = $this->data->toIdentifier();
71 12
        }
72
73 12
        if (! empty($this->meta)) {
74
            $array['meta'] = $this->meta;
75
        }
76
77 12
        if (! empty($this->links)) {
78
            $array['links'] = $this->links;
79
        }
80
81 12
        return $array;
82
    }
83
}
84