Completed
Push — master ( 883f28...097345 )
by Vincent
03:45 queued 11s
created

DocumentFactory   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 91.3%

Importance

Changes 0
Metric Value
wmc 10
eloc 26
dl 0
loc 81
ccs 21
cts 23
cp 0.913
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setJsonapi() 0 5 1
B toArray() 0 24 7
A fake() 0 3 1
A setIncluded() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiFaker\Factory;
6
7
use VGirol\JsonApiFaker\Members;
8
9
class DocumentFactory extends BaseFactory
10
{
11
    use HasData;
0 ignored issues
show
Bug introduced by
The trait VGirol\JsonApiFaker\Factory\HasData requires the property $boolean which is not provided by VGirol\JsonApiFaker\Factory\DocumentFactory.
Loading history...
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 2
    public function setIncluded($included)
37
    {
38 2
        $this->included = $included;
39
40 2
        return $this;
41
    }
42
43
    /**
44
     * Undocumented function
45
     *
46
     * @param JsonapiFactory $jsonapi
47
     * @return static
48
     */
49 3
    public function setJsonapi($jsonapi)
50
    {
51 3
        $this->jsonapi = $jsonapi;
52
53 3
        return $this;
54
    }
55
56 2
    public function toArray(): array
57
    {
58 2
        $json = [];
59
60 2
        if (isset($this->meta)) {
61 2
            $json[Members::META] = $this->meta;
62
        }
63 2
        if (isset($this->links)) {
64 2
            $json[Members::LINKS] = $this->links;
65
        }
66 2
        if (isset($this->errors)) {
67 1
            $json[Members::ERRORS] = $this->errors;
68
        }
69 2
        if (isset($this->data)) {
70 1
            $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 2
        if (isset($this->included)) {
73 1
            $json[Members::INCLUDED] = $this->included->toArray();
74
        }
75 2
        if (isset($this->jsonapi)) {
76 2
            $json[Members::JSONAPI] = $this->jsonapi;
77
        }
78
79 2
        return $json;
80
    }
81
82
    /**
83
     * Undocumented function
84
     *
85
     * @return static
86
     */
87
    public function fake()
88
    {
89
        return $this;
90
    }
91
}
92