Completed
Branch next (92e3a0)
by Neomerx
01:44
created

RelationshipDataIsIdentifier::isCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
nc 1
nop 0
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Neomerx\JsonApi\Parser\RelationshipData;
4
5
/**
6
 * Copyright 2015-2019 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Neomerx\JsonApi\Contracts\Factories\FactoryInterface;
22
use Neomerx\JsonApi\Contracts\Parser\IdentifierInterface as ParserIdentifierInterface;
23
use Neomerx\JsonApi\Contracts\Parser\PositionInterface;
24
use Neomerx\JsonApi\Contracts\Parser\RelationshipDataInterface;
25
use Neomerx\JsonApi\Contracts\Parser\ResourceInterface;
26
use Neomerx\JsonApi\Contracts\Schema\IdentifierInterface as SchemaIdentifierInterface;
27
use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface;
28
use Neomerx\JsonApi\Exceptions\LogicException;
29
use function Neomerx\JsonApi\I18n\format as _;
30
31
/**
32
 * @package Neomerx\JsonApi
33
 */
34
class RelationshipDataIsIdentifier extends BaseRelationshipData implements RelationshipDataInterface
35
{
36
    /** @var string */
37
    public const MSG_INVALID_OPERATION = 'Invalid operation.';
38
39
    /**
40
     * @var mixed
41
     */
42
    private $identifier;
43
44
    /**
45
     * @var null|ParserIdentifierInterface
46
     */
47
    private $parsedIdentifier = null;
48
49
    /**
50
     * @param FactoryInterface          $factory
51
     * @param SchemaContainerInterface  $schemaContainer
52
     * @param PositionInterface         $position
53
     * @param SchemaIdentifierInterface $identifier
54
     */
55 1
    public function __construct(
56
        FactoryInterface $factory,
57
        SchemaContainerInterface $schemaContainer,
58
        PositionInterface $position,
59
        SchemaIdentifierInterface $identifier
60
    ) {
61 1
        parent::__construct($factory, $schemaContainer, $position);
62
63 1
        $this->identifier = $identifier;
64 1
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69
    public function isCollection(): bool
70
    {
71
        return false;
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77
    public function isNull(): bool
78
    {
79
        return false;
80
    }
81
82
    /**
83
     * @inheritdoc
84
     */
85 1
    public function isResource(): bool
86
    {
87 1
        return false;
88
    }
89
90
    /**
91
     * @inheritdoc
92
     */
93 1
    public function isIdentifier(): bool
94
    {
95 1
        return true;
96
    }
97
98
    /**
99
     * @inheritdoc
100
     */
101 1
    public function getIdentifier(): ParserIdentifierInterface
102
    {
103 1
        if ($this->parsedIdentifier === null) {
104 1
            $this->parsedIdentifier = $this->createParsedIdentifier($this->identifier);
105
        }
106
107 1
        return $this->parsedIdentifier;
108
    }
109
110
    /**
111
     * @inheritdoc
112
     */
113
    public function getIdentifiers(): iterable
114
    {
115
        throw new LogicException(_(static::MSG_INVALID_OPERATION));
116
    }
117
118
    /**
119
     * @inheritdoc
120
     */
121
    public function getResource(): ResourceInterface
122
    {
123
        throw new LogicException(_(static::MSG_INVALID_OPERATION));
124
    }
125
126
    /**
127
     * @inheritdoc
128
     */
129
    public function getResources(): iterable
130
    {
131
        throw new LogicException(_(static::MSG_INVALID_OPERATION));
132
    }
133
}
134