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

AbstractRelationship   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 14 14 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}