ResourceIdentifierFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fake() 0 4 1
A toArray() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiFaker\Factory;
6
7
use VGirol\JsonApiConstant\Members;
8
use VGirol\JsonApiFaker\Contract\ResourceIdentifierContract;
9
10
/**
11
 * A factory for resource identifier object
12
 */
13
class ResourceIdentifierFactory extends BaseFactory implements ResourceIdentifierContract
14
{
15 1
    use HasIdentification;
16 1
    use HasMeta;
17
18
    /**
19
     * @return array
20
     */
21 48
    public function toArray(): array
22
    {
23 48
        $resource = [];
24 48
        $identification = $this->getIdentification();
25 48
        if ($identification !== null) {
26 42
            $resource = $identification;
27
        }
28
29 48
        if (isset($this->meta)) {
30 30
            $resource[Members::META] = $this->meta;
31
        }
32
33 48
        return $resource;
34
    }
35
36
    /**
37
     * Fill the resource identifier object with fake values ("type", "id" and "meta").
38
     *
39
     * @return static
40
     */
41 36
    public function fake()
42
    {
43 36
        return $this->fakeIdentification()
44 36
            ->fakeMeta();
45
    }
46
}
47