Completed
Push — master ( 285fdb...fc4358 )
by Hans
02:33
created

PagedList::hasNext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Pinterest PHP library.
5
 *
6
 * (c) Hans Ott <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.md.
10
 *
11
 * Source: https://github.com/hansott/pinterest-php
12
 */
13
14
namespace Pinterest\Objects;
15
16
use InvalidArgumentException;
17
18
/**
19
 * This class represents a paged list.
20
 *
21
 * @author Hans Ott <[email protected]>
22
 */
23
final class PagedList
24
{
25
    /**
26
     * The paged list items.
27
     *
28
     * @var array
29
     */
30
    private $items;
31
32
    /**
33
     * The url for retrieving the next set of items.
34
     *
35
     * @var string
36
     */
37
    private $nextUrl;
38
39
    /**
40
     * Creates a new paged list.
41
     *
42
     * @param array  $items   The paged list items.
43
     * @param string $nextUrl The url for retrieving the next set of items.
44
     */
45 14
    public function __construct(array $items = array(), $nextUrl = null)
46
    {
47 14
        $this->guardThatTheseAreAllPinterestObjects($items);
48 14
        $this->items = $items;
49 14
        $this->nextUrl = $nextUrl;
50 14
    }
51
52
    /**
53
     * Returns the items.
54
     *
55
     * @return array The items.
56
     */
57 14
    public function items()
58
    {
59 14
        return $this->items;
60
    }
61
62
    /**
63
     * Returns whether the paged list has more items.
64
     *
65
     * @return bool Whether there are more items.
66
     */
67
    public function hasNext()
68
    {
69
        return !empty($this->nextUrl);
70
    }
71
72
    /**
73
     * Returns the url to get the next set of items.
74
     *
75
     * @return string The url to get the next set of items.
76
     */
77
    public function getNextUrl()
78
    {
79
        return $this->nextUrl;
80
    }
81
82
    /**
83
     * Checks if all items are pinterest objects.
84
     *
85
     * @param array $items
86
     *
87
     * @throws InvalidArgumentException
88
     */
89 14
    private function guardThatTheseAreAllPinterestObjects(array $items)
90
    {
91 14
        foreach ($items as $item) {
92 12
            if (! ($item instanceof BaseObject)) {
93
                throw new InvalidArgumentException(sprintf(
94
                    'Expected "Pinterest\Objects\BaseObject" but instead got: "%s"',
95
                    is_object($item) ? get_class($item) : gettype($item)
96
                ));
97
            }
98 14
        }
99 14
    }
100
}
101