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

Attribute   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 57
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getNameInScheme() 0 4 1
A getScheme() 0 4 1
A getNameInModel() 0 8 2
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\AttributeInterface;
20
use Limoncello\Flute\Contracts\Schema\SchemaInterface;
21
22
/**
23
 * @package Limoncello\Flute
24
 */
25
class Attribute implements AttributeInterface
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 $scheme;
41
42
    /**
43
     * @param string          $nameInScheme
44
     * @param SchemaInterface $scheme
45
     */
46 9
    public function __construct(string $nameInScheme, SchemaInterface $scheme)
47
    {
48 9
        $this->nameInScheme = $nameInScheme;
49 9
        $this->scheme       = $scheme;
50
51 9
        $this->nameInModel = null;
52
    }
53
54
    /**
55
     * @return string
56
     */
57 9
    public function getNameInScheme(): string
58
    {
59 9
        return $this->nameInScheme;
60
    }
61
62
    /**
63
     * @return SchemaInterface
64
     */
65 9
    public function getScheme(): SchemaInterface
66
    {
67 9
        return $this->scheme;
68
    }
69
70
    /**
71
     * @return string
72
     */
73 7
    public function getNameInModel():string
74
    {
75 7
        if ($this->nameInModel === null) {
76 7
            $this->nameInModel = $this->getScheme()->getAttributeMapping($this->getNameInScheme());
77
        }
78
79 7
        return $this->nameInModel;
80
    }
81
}
82