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

AbstractRelationship::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 0
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 View Code Duplication
abstract class AbstractRelationship implements MetadataAwareInterface, LinksAwareInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23
    use MetadataContainer;
24
    use LinksContainer;
25
26
    /**
27
     * Cast to an array
28
     *
29
     * @return array
30
     */
31
    public function toArray(): array
32
    {
33
        $data = [];
34
35
        if ($this->hasMetadata()) {
36
            $data['meta'] = $this->getMetadata();
37
        }
38
39
        if ($this->hasLinks()) {
40
            $data['links'] = $this->linksToArray();
41
        }
42
43
        return $data;
44
    }
45
}