Completed
Push — master ( b6f561...db9bd8 )
by Neomerx
03:16
created

Relationship   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 75
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getNameInScheme() 0 4 1
A getNameInModel() 0 8 2
A getFromSchema() 0 4 1
A getToSchema() 0 4 1
1
<?php namespace Limoncello\Flute\Http\Query;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Flute\Contracts\Http\Query\RelationshipInterface;
20
use Limoncello\Flute\Contracts\Schema\SchemaInterface;
21
22
/**
23
 * @package Limoncello\Flute
24
 */
25
class Relationship implements RelationshipInterface
26
{
27
    /**
28
     * @var string
29
     */
30
    private $nameInScheme;
31
32
    /**
33
     * @var string
34
     */
35
    private $nameInModel;
36
37
    /**
38
     * @var SchemaInterface
39
     */
40
    private $fromSchema;
41
42
    /**
43
     * @var SchemaInterface
44
     */
45
    private $toSchema;
46
47
    /**
48
     * @param string          $nameInScheme
49
     * @param SchemaInterface $fromSchema
50
     * @param SchemaInterface $toSchema
51
     */
52 9
    public function __construct(
53
        string $nameInScheme,
54
        SchemaInterface $fromSchema,
55
        SchemaInterface $toSchema
56
    ) {
57 9
        $this->nameInScheme = $nameInScheme;
58 9
        $this->fromSchema   = $fromSchema;
59 9
        $this->toSchema     = $toSchema;
60
61 9
        $this->nameInModel = null;
62
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67 9
    public function getNameInScheme(): string
68
    {
69 9
        return $this->nameInScheme;
70
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75 8
    public function getNameInModel(): string
76
    {
77 8
        if ($this->nameInModel === null) {
78 8
            $this->nameInModel = $this->getFromSchema()->getRelationshipMapping($this->getNameInScheme());
79
        }
80
81 8
        return $this->nameInModel;
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87 9
    public function getFromSchema(): SchemaInterface
88
    {
89 9
        return $this->fromSchema;
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95 3
    public function getToSchema(): SchemaInterface
96
    {
97 3
        return $this->toSchema;
98
    }
99
}
100