Passed
Push — master ( 6b2979...464731 )
by Alex
04:00 queued 11s
created

ODataFeed::setRowCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace POData\ObjectModel;
6
7
/**
8
 * Class ODataFeed.
9
 */
10
class ODataFeed extends ODataContainerBase
11
{
12
    /**
13
     * Row count, in case of $inlinecount option.
14
     *
15
     * @var int
16
     */
17
    private $rowCount = null;
18
19
    /**
20
     * Enter URL to next page, if pagination is enabled.
21
     *
22
     * @var ODataNextPageLink
23
     */
24
    private $nextPageLink = null;
25
    /**
26
     * Collection of entries under this feed.
27
     *
28
     * @var ODataEntry[]
29
     */
30
    private $entries = [];
31
32
    /**
33
     * ODataFeed constructor.
34
     * @param string       $id
35
     * @param ODataTitle   $title
36
     * @param ODataLink    $selfLink
37
     * @param int          $rowCount
38
     * @param ODataLink    $nextPageLink
39
     * @param ODataEntry[] $entries
40
     * @param string       $updated
41
     * @param string       $baseURI
42
     */
43
    public function __construct(string $id = null, ODataTitle $title = null, ODataLink $selfLink = null, int $rowCount = null, ODataNextPageLink $nextPageLink = null, array $entries = [], string $updated = null, string $baseURI = null)
44
    {
45
        parent::__construct($id, $title, $selfLink, $updated, $baseURI);
46
        $this
47
            ->setRowCount($rowCount)
48
            ->setNextPageLink($nextPageLink)
49
            ->setEntries($entries);
50
    }
51
52
53
    /**
54
     * @return int
55
     */
56
    public function getRowCount(): ?int
57
    {
58
        return $this->rowCount;
59
    }
60
61
    /**
62
     * @param  int       $rowCount
63
     * @return ODataFeed
64
     */
65
    public function setRowCount(?int $rowCount): ODataFeed
66
    {
67
        $this->rowCount = $rowCount;
68
        return $this;
69
    }
70
71
    /**
72
     * @return ODataLink
73
     */
74
    public function getNextPageLink(): ?ODataLink
75
    {
76
        return $this->nextPageLink;
77
    }
78
79
    /**
80
     * @param  ODataLink|null $nextPageLink
81
     * @return ODataFeed
82
     */
83
    public function setNextPageLink(?ODataLink $nextPageLink): self
84
    {
85
        $this->nextPageLink = null === $nextPageLink || $nextPageLink->isEmpty() ? null : $nextPageLink;
86
        return $this;
87
    }
88
89
    /**
90
     * @return ODataEntry[]
91
     */
92
    public function getEntries(): array
93
    {
94
        return $this->entries;
95
    }
96
97
    /**
98
     * @param  ODataEntry[] $entries
99
     * @return ODataFeed
100
     */
101
    public function setEntries(array $entries): self
102
    {
103
        assert(array_reduce($entries, function ($carry, $item) {
104
            return  $carry & $item instanceof ODataEntry;
105
        }, true));
106
        $this->entries = $entries;
107
        return $this;
108
    }
109
110
    /**
111
     * @param  ODataEntry $entry
112
     * @return ODataFeed
113
     */
114
    public function addEntry(ODataEntry $entry): self
115
    {
116
        $this->entries[] = $entry;
117
        return $this;
118
    }
119
}
120