Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
12 / 14
71.43% covered (warning)
71.43%
5 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
IndexRedirectContent
85.71% covered (warning)
85.71%
12 / 14
71.43% covered (warning)
71.43%
5 / 7
9.24
0.00% covered (danger)
0.00%
0 / 1
 __construct
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
 isValid
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 equals
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getTextForSummary
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRedirectTarget
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 updateRedirect
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace ProofreadPage\Index;
4
5use InvalidArgumentException;
6use MediaWiki\Content\Content;
7use MediaWiki\Content\TextContent;
8use MediaWiki\Title\Title;
9
10/**
11 * @license GPL-2.0-or-later
12 *
13 * A redirection in an Index: page
14 */
15class IndexRedirectContent extends TextContent {
16
17    /**
18     * @var Title
19     */
20    private $redirectionTarget;
21
22    /**
23     * @param Title $redirectionTarget
24     */
25    public function __construct( Title $redirectionTarget ) {
26        if ( !$redirectionTarget->isValidRedirectTarget() ) {
27            throw new InvalidArgumentException( $redirectionTarget . ' should be a valid redirection target' );
28        }
29        $this->redirectionTarget = $redirectionTarget;
30        parent::__construct(
31            '#REDIRECT [[' . $redirectionTarget->getFullText() . ']]',
32            CONTENT_MODEL_PROOFREAD_INDEX
33        );
34    }
35
36    /**
37     * @inheritDoc
38     */
39    public function isValid() {
40        return true;
41    }
42
43    /**
44     * @inheritDoc
45     */
46    public function getSize() {
47        return strlen( $this->redirectionTarget->getFullText() );
48    }
49
50    /**
51     * @inheritDoc
52     */
53    public function equals( ?Content $that = null ) {
54        return $that instanceof IndexRedirectContent &&
55            $this->redirectionTarget->equals( $that->getRedirectTarget() );
56    }
57
58    /**
59     * @inheritDoc
60     */
61    public function getTextForSummary( $maxlength = 250 ) {
62        return '';
63    }
64
65    /**
66     * @inheritDoc
67     * @return Title
68     */
69    public function getRedirectTarget() {
70        return $this->redirectionTarget;
71    }
72
73    /**
74     * @inheritDoc
75     */
76    public function updateRedirect( Title $target ) {
77        return new self( $target );
78    }
79}