Relationship::getFromSchema()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
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 declare (strict_types = 1);
2
3
namespace Limoncello\Flute\Http\Query;
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 Limoncello\Flute\Contracts\Http\Query\RelationshipInterface;
22
use Limoncello\Flute\Contracts\Schema\SchemaInterface;
23
24
/**
25
 * @package Limoncello\Flute
26
 */
27
class Relationship implements RelationshipInterface
28
{
29
    /**
30
     * @var string
31
     */
32
    private $nameInSchema;
33
34
    /**
35
     * @var string
36
     */
37
    private $nameInModel;
38
39
    /**
40
     * @var SchemaInterface
41
     */
42
    private $fromSchema;
43
44
    /**
45
     * @var SchemaInterface
46
     */
47
    private $toSchema;
48
49
    /**
50
     * @param string          $nameInSchema
51
     * @param SchemaInterface $fromSchema
52
     * @param SchemaInterface $toSchema
53
     */
54 10
    public function __construct(
55
        string $nameInSchema,
56
        SchemaInterface $fromSchema,
57
        SchemaInterface $toSchema
58
    ) {
59 10
        $this->nameInSchema = $nameInSchema;
60 10
        $this->fromSchema   = $fromSchema;
61 10
        $this->toSchema     = $toSchema;
62
63 10
        $this->nameInModel = null;
64
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69 10
    public function getNameInSchema(): string
70
    {
71 10
        return $this->nameInSchema;
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77 9
    public function getNameInModel(): string
78
    {
79 9
        if ($this->nameInModel === null) {
80 9
            $this->nameInModel = $this->getFromSchema()->getRelationshipMapping($this->getNameInSchema());
81
        }
82
83 9
        return $this->nameInModel;
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89 10
    public function getFromSchema(): SchemaInterface
90
    {
91 10
        return $this->fromSchema;
92
    }
93
94
    /**
95
     * @inheritdoc
96
     */
97 3
    public function getToSchema(): SchemaInterface
98
    {
99 3
        return $this->toSchema;
100
    }
101
}
102