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

ResourceObjectFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 26
dl 0
loc 53
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fake() 0 7 1
A toArray() 0 26 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiFaker\Factory;
6
7
use VGirol\JsonApiFaker\Members;
8
9
class ResourceObjectFactory extends BaseFactory
10
{
11
    use HasIdentification;
0 ignored issues
show
Bug introduced by
The trait VGirol\JsonApiFaker\Factory\HasIdentification requires the property $word which is not provided by VGirol\JsonApiFaker\Factory\ResourceObjectFactory.
Loading history...
12
    use HasMeta;
13
    use HasLinks;
14
    use HasAttributes;
15
    use HasRelationships;
16
17
    /**
18
     * Undocumented function
19
     *
20
     * @return array
21
     */
22 7
    public function toArray(): array
23
    {
24 7
        $resource = $this->getIdentification();
25 7
        if (is_null($resource)) {
26 1
            $resource = [];
27
        }
28
29 7
        if (isset($this->attributes)) {
30 6
            $resource[Members::ATTRIBUTES] = $this->attributes;
31
        }
32 7
        if (isset($this->meta)) {
33 5
            $resource[Members::META] = $this->meta;
34
        }
35 7
        if (isset($this->links)) {
36 4
            $resource[Members::LINKS] = $this->links;
37
        }
38 7
        if (isset($this->relationships)) {
39 5
            $resource[Members::RELATIONSHIPS] = array_map(
40
                function ($relationship) {
41 5
                    return $relationship->toArray();
42 5
                },
43 5
                $this->relationships
44
            );
45
        }
46
47 7
        return $resource;
48
    }
49
50
    /**
51
     * Undocumented function
52
     *
53
     * @return static
54
     */
55 4
    public function fake()
56
    {
57 4
        return $this->fakeIdentification()
58 4
            ->fakeAttributes()
59 4
            ->fakeMeta()
60 4
            ->fakeLinks()
61 4
            ->fakeRelationships();
62
    }
63
}
64