Passed
Push — master ( 92cbc5...dc473e )
by Michael
02:54
created

AbstractDocument   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 18 4
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Component\JsonApi\Document;
5
6
use Mikemirten\Component\JsonApi\Document\Behaviour\ErrorsContainer;
7
use Mikemirten\Component\JsonApi\Document\Behaviour\LinksAwareInterface;
8
use Mikemirten\Component\JsonApi\Document\Behaviour\LinksContainer;
9
use Mikemirten\Component\JsonApi\Document\Behaviour\MetadataAwareInterface;
10
use Mikemirten\Component\JsonApi\Document\Behaviour\MetadataContainer;
11
12
/**
13
 * Abstract Document
14
 *
15
 * @see http://jsonapi.org/format/#document-structure
16
 *
17
 * Represents base JsonAPI-document structure
18
 * Supposed to be extended by case-based documents
19
 *
20
 * @package Mikemirten\Component\JsonApi\Document
21
 */
22
abstract class AbstractDocument implements MetadataAwareInterface, LinksAwareInterface
23
{
24
    use MetadataContainer;
25
    use LinksContainer;
26
    use ErrorsContainer;
27
28
    /**
29
     * Cast to an array
30
     *
31
     * @return array
32
     */
33 15
    public function toArray(): array
34
    {
35 15
        $data = [];
36
37 15
        if ($this->hasMetadata()) {
38 4
            $data['meta'] = $this->getMetadata();
39
        }
40
41 15
        if ($this->hasLinks()) {
42 4
            $data['links'] = $this->linksToArray();
43
        }
44
45 15
        if ($this->hasErrors()) {
46 4
            $data['errors'] = $this->errorsToArray();
47
        }
48
49 15
        return $data;
50
    }
51
}