Completed
Push — develop ( db9bd8...90d90f )
by Neomerx
04:13 queued 02:35
created

PaginatedData::markAsSingleItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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 29
    public function __construct($data)
45
    {
46 29
        $this->data = $data;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52 29
    public function getData()
53
    {
54 29
        return $this->data;
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60 18
    public function isCollection(): bool
61
    {
62 18
        return $this->isCollection;
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68 29
    public function markAsCollection(): PaginatedDataInterface
69
    {
70 29
        $this->isCollection = true;
71
72 29
        return $this;
73
    }
74
75
    /**
76
     * @inheritdoc
77
     */
78 1
    public function markAsSingleItem(): PaginatedDataInterface
79
    {
80 1
        $this->isCollection = false;
81
82 1
        return $this;
83
    }
84
85
    /**
86
     * @inheritdoc
87
     */
88 19
    public function hasMoreItems(): bool
89
    {
90 19
        return $this->hasMoreItems;
91
    }
92
93
    /**
94
     * @inheritdoc
95
     */
96 8
    public function markHasMoreItems(): PaginatedDataInterface
97
    {
98 8
        $this->hasMoreItems = true;
99
100 8
        return $this;
101
    }
102
103
    /**
104
     * @inheritdoc
105
     */
106 26
    public function markHasNoMoreItems(): PaginatedDataInterface
107
    {
108 26
        $this->hasMoreItems = false;
109
110 26
        return $this;
111
    }
112
113
    /**
114
     * @inheritdoc
115
     */
116 20
    public function getOffset(): ?int
117
    {
118 20
        return $this->offset;
119
    }
120
121
    /**
122
     * @inheritdoc
123
     */
124 29
    public function setOffset(int $offset = null): PaginatedDataInterface
125
    {
126 29
        $this->offset = $offset;
127
128 29
        return $this;
129
    }
130
131
    /**
132
     * @inheritdoc
133
     */
134 11
    public function getLimit(): ?int
135
    {
136 11
        return $this->size;
137
    }
138
139
    /**
140
     * @inheritdoc
141
     */
142 29
    public function setLimit(int $size = null): PaginatedDataInterface
143
    {
144 29
        $this->size = $size;
145
146 29
        return $this;
147
    }
148
}
149