SingleIdentifierDocument::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Component\JsonApi\Document;
5
6
/**
7
 * Single resource identifier document
8
 *
9
 * @see http://jsonapi.org/format/#document-structure
10
 *
11
 * @package Mikemirten\Component\JsonApi\Document
12
 */
13 View Code Duplication
class SingleIdentifierDocument extends AbstractDocument
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * Resource identifier
17
     *
18
     * @var ResourceIdentifierObject
19
     */
20
    protected $identifier;
21
22
    /**
23
     * SingleResourceDocument constructor.
24
     *
25
     * @param ResourceIdentifierObject $resource
26
     * @param array                    $metadata
27
     */
28 19
    public function __construct(ResourceIdentifierObject $resource, array $metadata = [])
29
    {
30 19
        $this->identifier = $resource;
31 19
        $this->metadata   = $metadata;
32 19
    }
33
34
    /**
35
     * Get resource identifier
36
     *
37
     * @return ResourceIdentifierObject
38
     */
39 7
    public function getIdentifier(): ResourceIdentifierObject
40
    {
41 7
        return $this->identifier;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 6
    public function toArray(): array
48
    {
49 6
        $data = parent::toArray();
50
51 6
        $data['data'] = $this->getIdentifier()->toArray();
52
53 6
        return $data;
54
    }
55
56
    /**
57
     * Cast to a string
58
     *
59
     * @return string
60
     */
61 5
    public function __toString(): string
62
    {
63 5
        return sprintf('Document contains [%s]', $this->identifier);
64
    }
65
}