JsonapiFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 12 3
A fake() 0 4 1
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\JsonapiContract;
9
10
/**
11
 * A Factory for the "jsonapi" object.
12
 */
13
class JsonapiFactory extends BaseFactory implements JsonapiContract
14
{
15 1
    use HasMeta;
16 1
    use HasVersion;
17
18
    /**
19
     * @return array|null
20
     */
21 18
    public function toArray(): ?array
22
    {
23 18
        $json = [];
24
25 18
        if (isset($this->version)) {
26 12
            $json[Members::JSONAPI_VERSION] = $this->version;
27
        }
28 18
        if (isset($this->meta)) {
29 6
            $json[Members::META] = $this->meta;
30
        }
31
32 18
        return $json;
33
    }
34
35
    /**
36
     * Fill the jsonapi object with fake values ("version" and "meta").
37
     *
38
     * @param int $countMeta
39
     *
40
     * @return static
41
     */
42 15
    public function fake(int $countMeta = 5)
43
    {
44 15
        return $this->fakeMeta($countMeta)
45 15
            ->fakeVersion();
46
    }
47
}
48