Completed
Push — master ( a787fa...dc9af5 )
by Vincent
05:35
created

DocumentFactory::toArray()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 24
rs 8.8333
cc 7
nc 64
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiAssert\Factory;
6
7
use VGirol\JsonApiAssert\Members;
8
9
class DocumentFactory extends BaseFactory
10
{
11
    use HasData;
12
    use HasErrors;
13
    use HasLinks;
14
    use HasMeta;
15
16
    /**
17
     * Undocumented variable
18
     *
19
     * @var CollectionFactory
20
     */
21
    public $included;
22
23
    /**
24
     * Undocumented variable
25
     *
26
     * @var JsonapiFactory
27
     */
28
    public $jsonapi;
29
30
    /**
31
     * Undocumented function
32
     *
33
     * @param CollectionFactory $included
34
     * @return static
35
     */
36
    public function setIncluded($included)
37
    {
38
        $this->included = $included;
39
40
        return $this;
41
    }
42
43
    /**
44
     * Undocumented function
45
     *
46
     * @param JsonapiFactory $jsonapi
47
     * @return static
48
     */
49
    public function setJsonapi($jsonapi)
50
    {
51
        $this->jsonapi = $jsonapi;
52
53
        return $this;
54
    }
55
56
    public function toArray(): array
57
    {
58
        $json = [];
59
60
        if (isset($this->meta)) {
61
            $json[Members::META] = $this->meta;
62
        }
63
        if (isset($this->links)) {
64
            $json[Members::LINKS] = $this->links;
65
        }
66
        if (isset($this->errors)) {
67
            $json[Members::ERRORS] = $this->errors;
68
        }
69
        if (isset($this->data)) {
70
            $json[Members::DATA] = $this->data->toArray();
0 ignored issues
show
Bug introduced by
The method toArray() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
            /** @scrutinizer ignore-call */ 
71
            $json[Members::DATA] = $this->data->toArray();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
        }
72
        if (isset($this->included)) {
73
            $json[Members::INCLUDED] = $this->included->toArray();
74
        }
75
        if (isset($this->jsonapi)) {
76
            $json[Members::JSONAPI] = $this->jsonapi;
77
        }
78
79
        return $json;
80
    }
81
}
82