Completed
Push — master ( 8f5342...8c413c )
by Jasper
15s queued 12s
created

AbstractOneRelation   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 84.21%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 67
ccs 16
cts 19
cp 0.8421
rs 10
c 1
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A associate() 0 4 1
A setIncluded() 0 5 1
A setData() 0 5 1
A getData() 0 3 2
A getAssociated() 0 11 3
A getIncluded() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Swis\JsonApi\Client\Relations;
6
7
use Swis\JsonApi\Client\Interfaces\ItemInterface;
8
use Swis\JsonApi\Client\Interfaces\OneRelationInterface;
9
10
/**
11
 * @property \Swis\JsonApi\Client\Interfaces\ItemInterface|false|null $data
12
 * @property \Swis\JsonApi\Client\Interfaces\ItemInterface|false|null $included
13
 */
14
abstract class AbstractOneRelation extends AbstractRelation implements OneRelationInterface
15
{
16
    /**
17
     * @param \Swis\JsonApi\Client\Interfaces\ItemInterface|null $data
18
     *
19
     * @return $this
20
     */
21 184
    public function setData(?ItemInterface $data)
22
    {
23 184
        $this->data = $data;
24
25 184
        return $this;
26
    }
27
28
    /**
29
     * @return \Swis\JsonApi\Client\Interfaces\ItemInterface|null
30
     */
31 12
    public function getData(): ?ItemInterface
32
    {
33 12
        return $this->data ?: null;
34
    }
35
36
    /**
37
     * @param \Swis\JsonApi\Client\Interfaces\ItemInterface|null $included
38
     *
39
     * @return $this
40
     */
41 184
    public function setIncluded(?ItemInterface $included)
42
    {
43 184
        $this->included = $included;
44
45 184
        return $this;
46
    }
47
48
    /**
49
     * @return \Swis\JsonApi\Client\Interfaces\ItemInterface|null
50
     */
51 148
    public function getIncluded(): ?ItemInterface
52
    {
53 148
        return $this->included ?: null;
54
    }
55
56
    /**
57
     * @param \Swis\JsonApi\Client\Interfaces\ItemInterface $included
58
     *
59
     * @return $this
60
     */
61 184
    public function associate(ItemInterface $included)
62
    {
63 184
        return $this->setData($included)
64 184
            ->setIncluded($included);
65
    }
66
67
    /**
68
     * @return \Swis\JsonApi\Client\Interfaces\ItemInterface|null
69
     */
70 64
    public function getAssociated(): ?ItemInterface
71
    {
72 64
        if ($this->hasIncluded()) {
73 64
            return $this->getIncluded();
74
        }
75
76
        if ($this->hasData()) {
77
            return $this->getData();
78
        }
79
80
        return null;
81
    }
82
}
83