SortParameter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getAttribute() 0 4 1
A getRelationship() 0 4 1
A isAsc() 0 4 1
A isDesc() 0 4 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\AttributeInterface;
22
use Limoncello\Flute\Contracts\Http\Query\RelationshipInterface;
23
use Limoncello\Flute\Contracts\Http\Query\SortParameterInterface;
24
25
/**
26
 * @package Limoncello\Flute
27
 */
28
class SortParameter implements SortParameterInterface
29
{
30
    /**
31
     * @var AttributeInterface
32
     */
33
    private $attribute;
34
35
    /**
36
     * @var RelationshipInterface|null
37
     */
38
    private $relationship;
39
40
    /**
41
     * @var bool
42
     */
43
    private $isAsc;
44
45
    /**
46
     * @param AttributeInterface         $attribute
47
     * @param bool                       $isAsc
48
     * @param RelationshipInterface|null $relationship
49
     */
50 5
    public function __construct(
51
        AttributeInterface $attribute,
52
        bool $isAsc,
53
        RelationshipInterface $relationship = null
54
    ) {
55 5
        $this->attribute    = $attribute;
56 5
        $this->relationship = $relationship;
57 5
        $this->isAsc        = $isAsc;
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63 5
    public function getAttribute(): AttributeInterface
64
    {
65 5
        return $this->attribute;
66
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71 5
    public function getRelationship(): ?RelationshipInterface
72
    {
73 5
        return $this->relationship;
74
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79 5
    public function isAsc(): bool
80
    {
81 5
        return $this->isAsc;
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87 1
    public function isDesc(): bool
88
    {
89 1
        return !$this->isAsc;
90
    }
91
}
92