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

PaginatedData::getOffset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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