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

ResourceObjectFactory::toArray()   A

Complexity

Conditions 6
Paths 32

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 26
ccs 16
cts 16
cp 1
rs 9.2222
c 0
b 0
f 0
cc 6
nc 32
nop 0
crap 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