Passed
Pull Request — release-11.5.x (#3206)
by Michael
41:07
created

ResultsPaginator::getAmountOfItemsOnCurrentPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Pagination;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
18
use TYPO3\CMS\Core\Pagination\AbstractPaginator;
19
20
/**
21
 * Class ResultsPaginator
22
 *
23
 * @author Rudy Gnodde <[email protected]>
24
 */
25
class ResultsPaginator extends AbstractPaginator
26
{
27
    /**
28
     * @var SearchResultSet
29
     */
30
    protected $resultSet;
31
32
    /**
33
     * @param SearchResultSet $resultSet
34
     * @param int $currentPageNumber
35
     * @param int $itemsPerPage
36
     */
37 32
    public function __construct(
38
        SearchResultSet $resultSet,
39
        int $currentPageNumber = 1,
40
        int $itemsPerPage = 10
41
    ) {
42 32
        $this->resultSet = $resultSet;
43 32
        $this->setCurrentPageNumber($currentPageNumber);
44 32
        $this->setItemsPerPage($itemsPerPage);
45
46 32
        $this->updateInternalState();
47
    }
48
49
    /**
50
     * Get paginated items
51
     *
52
     * @return iterable
53
     */
54
    public function getPaginatedItems(): iterable
55
    {
56
        return $this->resultSet->getSearchResults();
57
    }
58
59
    /**
60
     * Update paginated items
61
     *
62
     * @param int $itemsPerPage
63
     * @param int $offset
64
     */
65
    public function updatePaginatedItems(int $itemsPerPage, int $offset): void
66
    {
67
    }
68
69
    /**
70
     * Get amount of items on current page
71
     *
72
     * @return int
73
     */
74 32
    public function getAmountOfItemsOnCurrentPage(): int
75
    {
76 32
        return $this->resultSet->getSearchResults()->count();
77
    }
78
79
    /**
80
     * Get total amount of items
81
     *
82
     * @return int
83
     */
84 32
    public function getTotalAmountOfItems(): int
85
    {
86 32
        return $this->resultSet->getAllResultCount();
87
    }
88
89
}
90