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:
thiemowmde 2023-06-05 16:36:03 +02:00
parent f823468e1c
commit 5c93bbfd00
9 changed files with 36 additions and 126 deletions

View file

@ -9,14 +9,8 @@ use Sanitizer;
*/ */
class AnchorFormatter { class AnchorFormatter {
/** private ReferenceMessageLocalizer $messageLocalizer;
* @var ReferenceMessageLocalizer
*/
private $messageLocalizer;
/**
* @param ReferenceMessageLocalizer $messageLocalizer
*/
public function __construct( ReferenceMessageLocalizer $messageLocalizer ) { public function __construct( ReferenceMessageLocalizer $messageLocalizer ) {
$this->messageLocalizer = $messageLocalizer; $this->messageLocalizer = $messageLocalizer;
} }

View file

@ -44,51 +44,29 @@ class Cite {
*/ */
public const BOOK_REF_PROPERTY = 'ref-extends'; public const BOOK_REF_PROPERTY = 'ref-extends';
/** private bool $isSectionPreview;
* @var bool private FootnoteMarkFormatter $footnoteMarkFormatter;
*/ private ReferencesFormatter $referencesFormatter;
private $isSectionPreview; private ErrorReporter $errorReporter;
/**
* @var FootnoteMarkFormatter
*/
private $footnoteMarkFormatter;
/**
* @var ReferencesFormatter
*/
private $referencesFormatter;
/**
* @var ErrorReporter
*/
private $errorReporter;
/** /**
* True when a <ref> tag is being processed. * True when a <ref> tag is being processed.
* Used to avoid infinite recursion * 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 * @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! * 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> * Error stack used when defining refs in <references>
*
* @var string[] * @var string[]
*/ */
private $mReferencesErrors = []; private array $mReferencesErrors = [];
private ReferenceStack $referenceStack;
/**
* @var ReferenceStack
*/
private $referenceStack;
/** /**
* @param Parser $parser * @param Parser $parser

View file

@ -13,19 +13,9 @@ use Sanitizer;
*/ */
class ErrorReporter { class ErrorReporter {
/** private ReferenceMessageLocalizer $messageLocalizer;
* @var ReferenceMessageLocalizer private ?Language $cachedInterfaceLanguage = null;
*/
private $messageLocalizer;
/**
* @var Language
*/
private $cachedInterfaceLanguage = null;
/**
* @param ReferenceMessageLocalizer $messageLocalizer
*/
public function __construct( ReferenceMessageLocalizer $messageLocalizer ) { public function __construct( ReferenceMessageLocalizer $messageLocalizer ) {
$this->messageLocalizer = $messageLocalizer; $this->messageLocalizer = $messageLocalizer;
} }

View file

@ -10,31 +10,12 @@ use Sanitizer;
*/ */
class FootnoteMarkFormatter { class FootnoteMarkFormatter {
/** /** @var string[][] */
* @var string[][] private array $linkLabels = [];
*/ private AnchorFormatter $anchorFormatter;
private $linkLabels = []; 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( public function __construct(
ErrorReporter $errorReporter, ErrorReporter $errorReporter,
AnchorFormatter $anchorFormatter, AnchorFormatter $anchorFormatter,

View file

@ -12,14 +12,8 @@ use MessageSpecifier;
*/ */
class ReferenceMessageLocalizer implements MessageLocalizer { class ReferenceMessageLocalizer implements MessageLocalizer {
/** private Language $language;
* @var Language
*/
private $language;
/**
* @param Language $language
*/
public function __construct( Language $language ) { public function __construct( Language $language ) {
$this->language = $language; $this->language = $language;
} }

View file

@ -43,25 +43,20 @@ class ReferenceStack {
* *
* @var array[][] * @var array[][]
*/ */
private $refs = []; private array $refs = [];
/** /**
* Auto-incrementing sequence number for all <ref>, no matter which group * 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. * Counter for the number of refs in each group.
* @var int[] * @var int[]
*/ */
private $groupRefSequence = []; private array $groupRefSequence = [];
/** @var int[][] */
/** private array $extendsCount = [];
* @var int[][]
*/
private $extendsCount = [];
/** /**
* <ref> call stack * <ref> call stack
@ -71,17 +66,13 @@ class ReferenceStack {
* @var (array|false)[] * @var (array|false)[]
* @phan-var array<array{0:string,1:int,2:string,3:?string,4:?string,5:?string,6: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. * @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 ) { public function __construct( ErrorReporter $errorReporter ) {
$this->errorReporter = $errorReporter; $this->errorReporter = $errorReporter;
} }

View file

@ -18,27 +18,10 @@ class ReferencesFormatter {
* @var string[]|null * @var string[]|null
*/ */
private $backlinkLabels = 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( public function __construct(
ErrorReporter $errorReporter, ErrorReporter $errorReporter,
AnchorFormatter $anchorFormatter, AnchorFormatter $anchorFormatter,

View file

@ -43,9 +43,8 @@ class CiteIntegrationTest extends \MediaWikiIntegrationTestCase {
} }
); );
/** @var ReferenceStack $referenceStack */ $referenceStack = new ReferenceStack( $mockErrorReporter );
$referenceStack = TestingAccessWrapper::newFromObject( new ReferenceStack( $mockErrorReporter ) ); TestingAccessWrapper::newFromObject( $referenceStack )->refs = $initialRefs;
$referenceStack->refs = $initialRefs;
$referencesFormatter = $this->createMock( ReferencesFormatter::class ); $referencesFormatter = $this->createMock( ReferencesFormatter::class );
$referencesFormatter->method( 'formatReferences' )->willReturn( '<references />' ); $referencesFormatter->method( 'formatReferences' )->willReturn( '<references />' );

View file

@ -42,9 +42,8 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
) { ) {
/** @var ErrorReporter $errorReporter */ /** @var ErrorReporter $errorReporter */
$errorReporter = $this->createMock( ErrorReporter::class ); $errorReporter = $this->createMock( ErrorReporter::class );
/** @var ReferenceStack $stack */ $stack = new ReferenceStack( $errorReporter );
$stack = TestingAccessWrapper::newFromObject( new ReferenceStack( $errorReporter ) ); TestingAccessWrapper::newFromObject( $stack )->refs = $referencesStack;
$stack->refs = $referencesStack;
/** @var Cite $cite */ /** @var Cite $cite */
$cite = TestingAccessWrapper::newFromObject( $this->newCite() ); $cite = TestingAccessWrapper::newFromObject( $this->newCite() );
@ -498,9 +497,10 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
} }
); );
/** @var ReferenceStack $referenceStack */ $referenceStack = new ReferenceStack( $mockErrorReporter );
$referenceStack = TestingAccessWrapper::newFromObject( new ReferenceStack( $mockErrorReporter ) ); /** @var ReferenceStack $stackSpy */
$referenceStack->refs = $initialRefs; $stackSpy = TestingAccessWrapper::newFromObject( $referenceStack );
$stackSpy->refs = $initialRefs;
$mockFootnoteMarkFormatter = $this->createMock( FootnoteMarkFormatter::class ); $mockFootnoteMarkFormatter = $this->createMock( FootnoteMarkFormatter::class );
$mockFootnoteMarkFormatter->method( 'linkRef' )->willReturn( '<foot />' ); $mockFootnoteMarkFormatter->method( 'linkRef' )->willReturn( '<foot />' );
@ -516,7 +516,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
$result = $spy->guardedRef( $mockParser, $text, $argv ); $result = $spy->guardedRef( $mockParser, $text, $argv );
$this->assertSame( $expectOutput, $result ); $this->assertSame( $expectOutput, $result );
$this->assertSame( $expectedErrors, $spy->mReferencesErrors ); $this->assertSame( $expectedErrors, $spy->mReferencesErrors );
$this->assertSame( $expectedRefs, $referenceStack->refs ); $this->assertSame( $expectedRefs, $stackSpy->refs );
} }
public static function provideGuardedRef() { public static function provideGuardedRef() {