PaginatedData   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 0
dl 0
loc 125
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getData() 0 4 1
A isCollection() 0 4 1
A markAsCollection() 0 6 1
A markAsSingleItem() 0 6 1
A hasMoreItems() 0 4 1
A markHasMoreItems() 0 6 1
A markHasNoMoreItems() 0 6 1
A getOffset() 0 4 1
A setOffset() 0 6 1
A getLimit() 0 4 1
A setLimit() 0 6 1
1
<?php declare (strict_types = 1);
2
3
namespace Limoncello\Flute\Models;
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\Models\PaginatedDataInterface;
22
23
/**
24
 * @package Limoncello\Flute
25
 */
26
class PaginatedData implements PaginatedDataInterface
27
{
28
    /** @var  mixed */
29
    private $data;
30
31
    /** @var  bool */
32
    private $isCollection = false;
33
34
    /** @var  bool */
35
    private $hasMoreItems = false;
36
37
    /** @var  int|null */
38
    private $offset = null;
39
40
    /** @var  int|null */
41
    private $size = null;
42
43
    /**
44
     * @param mixed $data
45
     */
46 29
    public function __construct($data)
47
    {
48 29
        $this->data = $data;
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 29
    public function getData()
55
    {
56 29
        return $this->data;
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62 17
    public function isCollection(): bool
63
    {
64 17
        return $this->isCollection;
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70 29
    public function markAsCollection(): PaginatedDataInterface
71
    {
72 29
        $this->isCollection = true;
73
74 29
        return $this;
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80 1
    public function markAsSingleItem(): PaginatedDataInterface
81
    {
82 1
        $this->isCollection = false;
83
84 1
        return $this;
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90 20
    public function hasMoreItems(): bool
91
    {
92 20
        return $this->hasMoreItems;
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98 9
    public function markHasMoreItems(): PaginatedDataInterface
99
    {
100 9
        $this->hasMoreItems = true;
101
102 9
        return $this;
103
    }
104
105
    /**
106
     * @inheritdoc
107
     */
108 25
    public function markHasNoMoreItems(): PaginatedDataInterface
109
    {
110 25
        $this->hasMoreItems = false;
111
112 25
        return $this;
113
    }
114
115
    /**
116
     * @inheritdoc
117
     */
118 21
    public function getOffset(): ?int
119
    {
120 21
        return $this->offset;
121
    }
122
123
    /**
124
     * @inheritdoc
125
     */
126 29
    public function setOffset(int $offset = null): PaginatedDataInterface
127
    {
128 29
        $this->offset = $offset;
129
130 29
        return $this;
131
    }
132
133
    /**
134
     * @inheritdoc
135
     */
136 13
    public function getLimit(): ?int
137
    {
138 13
        return $this->size;
139
    }
140
141
    /**
142
     * @inheritdoc
143
     */
144 29
    public function setLimit(int $size = null): PaginatedDataInterface
145
    {
146 29
        $this->size = $size;
147
148 29
        return $this;
149
    }
150
}
151