Attribute   A
last analyzed

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