Merge "Add strict types to all class properties"

This commit is contained in:
jenkins-bot 2023-06-08 10:41:54 +00:00 committed by Gerrit Code Review
commit 5affadae9d
9 changed files with 36 additions and 126 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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;
}

View file

@ -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,

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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,

View file

@ -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 />' );

View file

@ -41,9 +41,8 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
$expected
) {
$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() );
@ -496,9 +495,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 />' );
@ -514,7 +514,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() {