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

RelationshipFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 18
dl 0
loc 46
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 14 4
A fake() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiFaker\Factory;
6
7
use VGirol\JsonApiFaker\Members;
8
9
class RelationshipFactory extends BaseFactory
10
{
11
    use HasMeta;
12
    use HasLinks;
13
    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\RelationshipFactory.
Loading history...
14
15
    /**
16
     * Undocumented function
17
     *
18
     * @return array
19
     */
20 11
    public function toArray(): array
21
    {
22 11
        $resource = [];
23
24 11
        $resource[Members::DATA] = is_null($this->data) ? $this->data : $this->data->toArray();
25
26 11
        if (isset($this->meta)) {
27 6
            $resource[Members::META] = $this->meta;
28
        }
29 11
        if (isset($this->links)) {
30 6
            $resource[Members::LINKS] = $this->links;
31
        }
32
33 11
        return $resource;
34
    }
35
36
    /**
37
     * Undocumented function
38
     *
39
     * @param integer $options
40
     * @param integer $count
41
     *
42
     * @return static
43
     */
44 6
    public function fake($options = null, $count = 5)
45
    {
46 6
        if (is_null($options)) {
47 6
            $options = self::FAKE_COLLECTION;
48
        }
49 6
        $options |= self::FAKE_RESOURCE_IDENTIFIER;
50 6
        $options &= ~self::FAKE_RESOURCE_OBJECT;
51
52 6
        return $this->fakeData($options, $count)
53 6
            ->fakeMeta()
54 6
            ->fakeLinks();
55
    }
56
}
57