Completed
Pull Request — master (#309)
by
unknown
03:02
created

Collection::getPaginator()   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 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the League\Fractal package.
5
 *
6
 * (c) Phil Sturgeon <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace League\Fractal\Resource;
13
14
use ArrayIterator;
15
use League\Fractal\Pagination\CursorInterface;
16
use League\Fractal\Pagination\PaginatorInterface;
17
18
/**
19
 * Resource Collection
20
 *
21
 * The data can be a collection of any sort of data, as long as the
22
 * "collection" is either array or an object implementing ArrayIterator.
23
 */
24
class Collection extends ResourceAbstract
25
{
26
    /**
27
     * A collection of data.
28
     *
29
     * @var array|ArrayIterator
30
     */
31
    protected $data;
32
33
    /**
34
     * A the paginator instance.
35
     *
36
     * @var PaginatorInterface
37
     */
38
    protected $paginator;
39
40
    /**
41
     * The cursor instance.
42
     *
43
     * @var CursorInterface
44
     */
45
    protected $cursor;
46
47
    /**
48
     * Get the paginator instance.
49
     *
50
     * @return PaginatorInterface
51
     */
52 5
    public function getPaginator()
53
    {
54 5
        return $this->paginator;
55
    }
56
57
    /**
58
     * Determine if the resource has a paginator implementation.
59
     *
60
     * @return bool
61
     */
62 23
    public function hasPaginator()
63
    {
64 23
        return $this->paginator instanceof PaginatorInterface;
65
    }
66
67
    /**
68
     * Get the cursor instance.
69
     *
70
     * @return CursorInterface
71
     */
72 2
    public function getCursor()
73
    {
74 2
        return $this->cursor;
75
    }
76
77
    /**
78
     * Determine if the resource has a cursor implementation.
79
     *
80
     * @return bool
81
     */
82 24
    public function hasCursor()
83
    {
84 24
        return $this->cursor instanceof CursorInterface;
85
    }
86
87
    /**
88
     * Set the paginator instance.
89
     *
90
     * @param PaginatorInterface $paginator
91
     *
92
     * @return $this
93
     */
94 5
    public function setPaginator(PaginatorInterface $paginator)
95
    {
96 5
        $this->paginator = $paginator;
97
98 5
        return $this;
99
    }
100
101
    /**
102
     * Set the cursor instance.
103
     *
104
     * @param CursorInterface $cursor
105
     *
106
     * @return $this
107
     */
108 2
    public function setCursor(CursorInterface $cursor)
109
    {
110 2
        $this->cursor = $cursor;
111
112 2
        return $this;
113
    }
114
}
115