Passed
Branch 3.3 (6947f9)
by Pieter
03:45
created

PrimaryKeyReference   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 54
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getMetadata() 0 3 1
A getUrl() 0 3 1
A getIdentifierValue() 0 3 1
1
<?php
2
3
4
namespace W2w\Lib\Apie\Plugins\PrimaryKey\ValueObjects;
5
6
7
use W2w\Lib\Apie\Core\Models\ApiResourceClassMetadata;
8
use W2w\Lib\Apie\Interfaces\ValueObjectInterface;
9
10
/**
11
 * Value object for making a primary key reference to an Apie resource.
12
 */
13
final class PrimaryKeyReference
14
{
15
    /**
16
     * @var ApiResourceClassMetadata
17
     */
18
    private $metadata;
19
20
    /**
21
     * @var string
22
     */
23
    private $identifierValue;
24
25
    /**
26
     * @var string
27
     */
28
    private $resourceSlug;
29
30
    /**
31
     * @param ApiResourceClassMetadata $metadata
32
     * @param string|int|float|bool|object $identifierValue
33
     */
34
    public function __construct(ApiResourceClassMetadata $metadata, string $resourceSlug, $identifierValue)
35
    {
36
        $this->metadata = $metadata;
37
        $this->resourceSlug = $resourceSlug;
38
        if ($identifierValue instanceof ValueObjectInterface) {
39
            $this->identifierValue = (string) $identifierValue->toNative();
40
        } else {
41
            $this->identifierValue = (string) $identifierValue;
42
        }
43
    }
44
45
    /**
46
     * @return ApiResourceClassMetadata
47
     */
48
    public function getMetadata(): ApiResourceClassMetadata
49
    {
50
        return $this->metadata;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getUrl(): string
57
    {
58
        return $this->resourceSlug . '/' . $this->identifierValue;
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getIdentifierValue(): string
65
    {
66
        return $this->identifierValue;
67
    }
68
}
69