Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CampaignsPageFormatter
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getText
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3declare( strict_types=1 );
4
5namespace MediaWiki\Extension\CampaignEvents\MWEntity;
6
7use MediaWiki\Title\TitleFormatter;
8use UnexpectedValueException;
9
10/**
11 * This class formats a page, providing some string representation of it.
12 * @note This must work for cross-wiki pages, so getPrefixedText() cannot be here.
13 */
14class CampaignsPageFormatter {
15    public const SERVICE_NAME = 'CampaignEventsCampaignsPageFormatter';
16
17    private TitleFormatter $titleFormatter;
18
19    /**
20     * @param TitleFormatter $titleFormatter
21     */
22    public function __construct( TitleFormatter $titleFormatter ) {
23        $this->titleFormatter = $titleFormatter;
24    }
25
26    /**
27     * @param ICampaignsPage $page
28     * @return string
29     */
30    public function getText( ICampaignsPage $page ): string {
31        if ( $page instanceof MWPageProxy ) {
32            return $this->titleFormatter->getText( $page->getPageIdentity() );
33        }
34        throw new UnexpectedValueException( 'Unknown campaigns page implementation: ' . get_class( $page ) );
35    }
36}