Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.00% covered (warning)
85.00%
17 / 20
83.33% covered (warning)
83.33%
5 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
SimpleFilePagination
85.00% covered (warning)
85.00%
17 / 20
83.33% covered (warning)
83.33%
5 / 6
9.27
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getPageNumber
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 getDisplayedPageNumber
40.00% covered (danger)
40.00%
2 / 5
0.00% covered (danger)
0.00%
0 / 1
2.86
 getNumberOfPages
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPageTitle
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 pageNumberExists
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace ProofreadPage\Pagination;
4
5use MediaWiki\Title\Title;
6use OutOfBoundsException;
7
8/**
9 * @license GPL-2.0-or-later
10 *
11 * Pagination based on a single page file
12 */
13class SimpleFilePagination extends Pagination {
14
15    /** @var Title */
16    private $indexTitle;
17
18    /**
19     * @var PageList representation of the <pagelist> tag
20     */
21    private $pageList;
22
23    /** @var Title */
24    private $pageTitle;
25
26    /**
27     * @param Title $indexTitle
28     * @param PageList $pageList representation of the <pagelist> tag that configure page numbers
29     * @param int $pageNamespaceId
30     */
31    public function __construct(
32        Title $indexTitle, PageList $pageList, int $pageNamespaceId
33    ) {
34        $this->indexTitle = $indexTitle;
35        $this->pageTitle = Title::makeTitle( $pageNamespaceId, $this->indexTitle->getText() );
36        $this->pageList = $pageList;
37    }
38
39    /**
40     * @inheritDoc
41     */
42    public function getPageNumber( Title $pageTitle ): int {
43        if ( !$pageTitle->equals( $this->pageTitle ) ) {
44            throw new PageNotInPaginationException(
45                $pageTitle->getFullText() . ' does not belong to the pagination'
46            );
47        }
48        return 1;
49    }
50
51    /**
52     * @inheritDoc
53     */
54    public function getDisplayedPageNumber( int $pageNumber ): PageNumber {
55        if ( !$this->pageNumberExists( $pageNumber ) ) {
56            throw new OutOfBoundsException(
57                'There is no page number ' . $pageNumber . ' in the pagination.'
58            );
59        }
60        return $this->pageList->getNumber( $pageNumber );
61    }
62
63    /**
64     * @inheritDoc
65     */
66    public function getNumberOfPages(): int {
67        return 1;
68    }
69
70    /**
71     * @inheritDoc
72     */
73    public function getPageTitle( int $pageNumber ): Title {
74        if ( !$this->pageNumberExists( $pageNumber ) ) {
75            throw new OutOfBoundsException(
76                'There is no page number ' . $pageNumber . ' in the pagination.'
77            );
78        }
79        return $this->pageTitle;
80    }
81
82    /**
83     * @inheritDoc
84     */
85    protected function pageNumberExists( int $pageNumber ): bool {
86        return $pageNumber === 1;
87    }
88
89}