mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-18 01:30:32 +00:00
Add strict types to all class properties
A good bunch of PHPDoc comments is obsolete when we use strict types. Change-Id: Ie0692fae4d96c749e9048f7e7c6931ec97998093
This commit is contained in:
parent
f823468e1c
commit
5c93bbfd00
|
@ -9,14 +9,8 @@ use Sanitizer;
|
|||
*/
|
||||
class AnchorFormatter {
|
||||
|
||||
/**
|
||||
* @var ReferenceMessageLocalizer
|
||||
*/
|
||||
private $messageLocalizer;
|
||||
private ReferenceMessageLocalizer $messageLocalizer;
|
||||
|
||||
/**
|
||||
* @param ReferenceMessageLocalizer $messageLocalizer
|
||||
*/
|
||||
public function __construct( ReferenceMessageLocalizer $messageLocalizer ) {
|
||||
$this->messageLocalizer = $messageLocalizer;
|
||||
}
|
||||
|
|
38
src/Cite.php
38
src/Cite.php
|
@ -44,51 +44,29 @@ class Cite {
|
|||
*/
|
||||
public const BOOK_REF_PROPERTY = 'ref-extends';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isSectionPreview;
|
||||
|
||||
/**
|
||||
* @var FootnoteMarkFormatter
|
||||
*/
|
||||
private $footnoteMarkFormatter;
|
||||
|
||||
/**
|
||||
* @var ReferencesFormatter
|
||||
*/
|
||||
private $referencesFormatter;
|
||||
|
||||
/**
|
||||
* @var ErrorReporter
|
||||
*/
|
||||
private $errorReporter;
|
||||
private bool $isSectionPreview;
|
||||
private FootnoteMarkFormatter $footnoteMarkFormatter;
|
||||
private ReferencesFormatter $referencesFormatter;
|
||||
private ErrorReporter $errorReporter;
|
||||
|
||||
/**
|
||||
* True when a <ref> tag is being processed.
|
||||
* Used to avoid infinite recursion
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $mInCite = false;
|
||||
private bool $mInCite = false;
|
||||
|
||||
/**
|
||||
* @var null|string The current group name while parsing nested <ref> in <references>. Null when
|
||||
* parsing <ref> outside of <references>. Warning, an empty string is a valid group name!
|
||||
*/
|
||||
private $inReferencesGroup = null;
|
||||
private ?string $inReferencesGroup = null;
|
||||
|
||||
/**
|
||||
* Error stack used when defining refs in <references>
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $mReferencesErrors = [];
|
||||
|
||||
/**
|
||||
* @var ReferenceStack
|
||||
*/
|
||||
private $referenceStack;
|
||||
private array $mReferencesErrors = [];
|
||||
private ReferenceStack $referenceStack;
|
||||
|
||||
/**
|
||||
* @param Parser $parser
|
||||
|
|
|
@ -13,19 +13,9 @@ use Sanitizer;
|
|||
*/
|
||||
class ErrorReporter {
|
||||
|
||||
/**
|
||||
* @var ReferenceMessageLocalizer
|
||||
*/
|
||||
private $messageLocalizer;
|
||||
private ReferenceMessageLocalizer $messageLocalizer;
|
||||
private ?Language $cachedInterfaceLanguage = null;
|
||||
|
||||
/**
|
||||
* @var Language
|
||||
*/
|
||||
private $cachedInterfaceLanguage = null;
|
||||
|
||||
/**
|
||||
* @param ReferenceMessageLocalizer $messageLocalizer
|
||||
*/
|
||||
public function __construct( ReferenceMessageLocalizer $messageLocalizer ) {
|
||||
$this->messageLocalizer = $messageLocalizer;
|
||||
}
|
||||
|
|
|
@ -10,31 +10,12 @@ use Sanitizer;
|
|||
*/
|
||||
class FootnoteMarkFormatter {
|
||||
|
||||
/**
|
||||
* @var string[][]
|
||||
*/
|
||||
private $linkLabels = [];
|
||||
/** @var string[][] */
|
||||
private array $linkLabels = [];
|
||||
private AnchorFormatter $anchorFormatter;
|
||||
private ErrorReporter $errorReporter;
|
||||
private ReferenceMessageLocalizer $messageLocalizer;
|
||||
|
||||
/**
|
||||
* @var AnchorFormatter
|
||||
*/
|
||||
private $anchorFormatter;
|
||||
|
||||
/**
|
||||
* @var ErrorReporter
|
||||
*/
|
||||
private $errorReporter;
|
||||
|
||||
/**
|
||||
* @var ReferenceMessageLocalizer
|
||||
*/
|
||||
private $messageLocalizer;
|
||||
|
||||
/**
|
||||
* @param ErrorReporter $errorReporter
|
||||
* @param AnchorFormatter $anchorFormatter
|
||||
* @param ReferenceMessageLocalizer $messageLocalizer
|
||||
*/
|
||||
public function __construct(
|
||||
ErrorReporter $errorReporter,
|
||||
AnchorFormatter $anchorFormatter,
|
||||
|
|
|
@ -12,14 +12,8 @@ use MessageSpecifier;
|
|||
*/
|
||||
class ReferenceMessageLocalizer implements MessageLocalizer {
|
||||
|
||||
/**
|
||||
* @var Language
|
||||
*/
|
||||
private $language;
|
||||
private Language $language;
|
||||
|
||||
/**
|
||||
* @param Language $language
|
||||
*/
|
||||
public function __construct( Language $language ) {
|
||||
$this->language = $language;
|
||||
}
|
||||
|
|
|
@ -43,25 +43,20 @@ class ReferenceStack {
|
|||
*
|
||||
* @var array[][]
|
||||
*/
|
||||
private $refs = [];
|
||||
private array $refs = [];
|
||||
|
||||
/**
|
||||
* Auto-incrementing sequence number for all <ref>, no matter which group
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $refSequence = 0;
|
||||
private int $refSequence = 0;
|
||||
|
||||
/**
|
||||
* Counter for the number of refs in each group.
|
||||
* @var int[]
|
||||
*/
|
||||
private $groupRefSequence = [];
|
||||
|
||||
/**
|
||||
* @var int[][]
|
||||
*/
|
||||
private $extendsCount = [];
|
||||
private array $groupRefSequence = [];
|
||||
/** @var int[][] */
|
||||
private array $extendsCount = [];
|
||||
|
||||
/**
|
||||
* <ref> call stack
|
||||
|
@ -71,17 +66,13 @@ class ReferenceStack {
|
|||
* @var (array|false)[]
|
||||
* @phan-var array<array{0:string,1:int,2:string,3:?string,4:?string,5:?string,6:array}|false>
|
||||
*/
|
||||
private $refCallStack = [];
|
||||
private array $refCallStack = [];
|
||||
|
||||
/**
|
||||
* @deprecated We should be able to push this responsibility to calling code.
|
||||
* @var ErrorReporter
|
||||
*/
|
||||
private $errorReporter;
|
||||
private ErrorReporter $errorReporter;
|
||||
|
||||
/**
|
||||
* @param ErrorReporter $errorReporter
|
||||
*/
|
||||
public function __construct( ErrorReporter $errorReporter ) {
|
||||
$this->errorReporter = $errorReporter;
|
||||
}
|
||||
|
|
|
@ -18,27 +18,10 @@ class ReferencesFormatter {
|
|||
* @var string[]|null
|
||||
*/
|
||||
private $backlinkLabels = null;
|
||||
private ErrorReporter $errorReporter;
|
||||
private AnchorFormatter $anchorFormatter;
|
||||
private ReferenceMessageLocalizer $messageLocalizer;
|
||||
|
||||
/**
|
||||
* @var ErrorReporter
|
||||
*/
|
||||
private $errorReporter;
|
||||
|
||||
/**
|
||||
* @var AnchorFormatter
|
||||
*/
|
||||
private $anchorFormatter;
|
||||
|
||||
/**
|
||||
* @var ReferenceMessageLocalizer
|
||||
*/
|
||||
private $messageLocalizer;
|
||||
|
||||
/**
|
||||
* @param ErrorReporter $errorReporter
|
||||
* @param AnchorFormatter $anchorFormatter
|
||||
* @param ReferenceMessageLocalizer $messageLocalizer
|
||||
*/
|
||||
public function __construct(
|
||||
ErrorReporter $errorReporter,
|
||||
AnchorFormatter $anchorFormatter,
|
||||
|
|
|
@ -43,9 +43,8 @@ class CiteIntegrationTest extends \MediaWikiIntegrationTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
/** @var ReferenceStack $referenceStack */
|
||||
$referenceStack = TestingAccessWrapper::newFromObject( new ReferenceStack( $mockErrorReporter ) );
|
||||
$referenceStack->refs = $initialRefs;
|
||||
$referenceStack = new ReferenceStack( $mockErrorReporter );
|
||||
TestingAccessWrapper::newFromObject( $referenceStack )->refs = $initialRefs;
|
||||
|
||||
$referencesFormatter = $this->createMock( ReferencesFormatter::class );
|
||||
$referencesFormatter->method( 'formatReferences' )->willReturn( '<references />' );
|
||||
|
|
|
@ -42,9 +42,8 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
|
|||
) {
|
||||
/** @var ErrorReporter $errorReporter */
|
||||
$errorReporter = $this->createMock( ErrorReporter::class );
|
||||
/** @var ReferenceStack $stack */
|
||||
$stack = TestingAccessWrapper::newFromObject( new ReferenceStack( $errorReporter ) );
|
||||
$stack->refs = $referencesStack;
|
||||
$stack = new ReferenceStack( $errorReporter );
|
||||
TestingAccessWrapper::newFromObject( $stack )->refs = $referencesStack;
|
||||
|
||||
/** @var Cite $cite */
|
||||
$cite = TestingAccessWrapper::newFromObject( $this->newCite() );
|
||||
|
@ -498,9 +497,10 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
/** @var ReferenceStack $referenceStack */
|
||||
$referenceStack = TestingAccessWrapper::newFromObject( new ReferenceStack( $mockErrorReporter ) );
|
||||
$referenceStack->refs = $initialRefs;
|
||||
$referenceStack = new ReferenceStack( $mockErrorReporter );
|
||||
/** @var ReferenceStack $stackSpy */
|
||||
$stackSpy = TestingAccessWrapper::newFromObject( $referenceStack );
|
||||
$stackSpy->refs = $initialRefs;
|
||||
|
||||
$mockFootnoteMarkFormatter = $this->createMock( FootnoteMarkFormatter::class );
|
||||
$mockFootnoteMarkFormatter->method( 'linkRef' )->willReturn( '<foot />' );
|
||||
|
@ -516,7 +516,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
|
|||
$result = $spy->guardedRef( $mockParser, $text, $argv );
|
||||
$this->assertSame( $expectOutput, $result );
|
||||
$this->assertSame( $expectedErrors, $spy->mReferencesErrors );
|
||||
$this->assertSame( $expectedRefs, $referenceStack->refs );
|
||||
$this->assertSame( $expectedRefs, $stackSpy->refs );
|
||||
}
|
||||
|
||||
public static function provideGuardedRef() {
|
||||
|
|
Loading…
Reference in a new issue