HasIdentification::getIdentification()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 3
nop 0
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiFaker\Factory;
6
7
use VGirol\JsonApiConstant\Members;
8
9
/**
10
 * Add identification ("type" and "id" members) to a factory.
11
 */
12
trait HasIdentification
13
{
14 1
    use HasIdentifier;
15 1
    use HasResourceType;
16
17
    /**
18
     * Get the identification ("type" and "id" members) as array
19
     *
20
     * @return array|null
21
     */
22 66
    public function getIdentification(): ?array
23
    {
24 66
        if (!isset($this->id) && !isset($this->resourceType)) {
25 12
            return null;
26
        }
27
28
        return [
29 54
            Members::TYPE => $this->resourceType,
30 54
            Members::ID => ($this->id === null) ? null : strval($this->id)
31
        ];
32
    }
33
34
    /**
35
     * Fill "type" and "id" members with fake values.
36
     *
37
     * @return static
38
     */
39 39
    public function fakeIdentification()
40
    {
41 39
        return $this->fakeResourceType()
42 39
            ->fakeIdentifier();
43
    }
44
}
45