Total Complexity | 7 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
13 | class ResourceObjectFactory extends BaseFactory implements ResourceObjectContract |
||
14 | { |
||
15 | 1 | use HasAttributes; |
|
16 | 1 | use HasIdentification; |
|
17 | 1 | use HasLinks; |
|
18 | 1 | use HasMeta; |
|
19 | 1 | use HasRelationships; |
|
20 | |||
21 | /** |
||
22 | * Exports the factory as an array. |
||
23 | * |
||
24 | * @return array |
||
25 | */ |
||
26 | 21 | public function toArray(): array |
|
27 | { |
||
28 | 21 | $resource = []; |
|
29 | 21 | $identification = $this->getIdentification(); |
|
30 | 21 | if ($identification !== null) { |
|
31 | 18 | $resource = $identification; |
|
32 | } |
||
33 | |||
34 | 21 | if (isset($this->attributes)) { |
|
35 | 18 | $resource[Members::ATTRIBUTES] = $this->attributes; |
|
36 | } |
||
37 | 21 | if (isset($this->meta)) { |
|
38 | 15 | $resource[Members::META] = $this->meta; |
|
39 | } |
||
40 | 21 | if (isset($this->links)) { |
|
41 | 12 | $resource[Members::LINKS] = $this->links; |
|
42 | } |
||
43 | 21 | if (isset($this->relationships)) { |
|
44 | 15 | $resource[Members::RELATIONSHIPS] = array_map( |
|
45 | /** |
||
46 | * @param RelationshipFactory $relationship |
||
47 | * @return array |
||
48 | */ |
||
49 | 15 | function ($relationship) { |
|
50 | 15 | return $relationship->toArray(); |
|
51 | 15 | }, |
|
52 | 15 | $this->relationships |
|
53 | ); |
||
54 | } |
||
55 | |||
56 | 21 | return $resource; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Fill the resource object with fake values ("type", "id", "attributes", "meta", "links" and "relationships"). |
||
61 | * |
||
62 | * @return static |
||
63 | */ |
||
64 | 15 | public function fake() |
|
71 | } |
||
72 | } |
||
73 |