diff --git a/src/AnchorFormatter.php b/src/AnchorFormatter.php index d0958eda8..d73b5589d 100644 --- a/src/AnchorFormatter.php +++ b/src/AnchorFormatter.php @@ -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; } diff --git a/src/Cite.php b/src/Cite.php index 7eff0c3f9..28c4b6b0d 100644 --- a/src/Cite.php +++ b/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 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 in . Null when * parsing outside of . Warning, an empty string is a valid group name! */ - private $inReferencesGroup = null; + private ?string $inReferencesGroup = null; /** * Error stack used when defining refs in - * * @var string[] */ - private $mReferencesErrors = []; - - /** - * @var ReferenceStack - */ - private $referenceStack; + private array $mReferencesErrors = []; + private ReferenceStack $referenceStack; /** * @param Parser $parser diff --git a/src/ErrorReporter.php b/src/ErrorReporter.php index d913f058a..2c646878e 100644 --- a/src/ErrorReporter.php +++ b/src/ErrorReporter.php @@ -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; } diff --git a/src/FootnoteMarkFormatter.php b/src/FootnoteMarkFormatter.php index 78a3a10ed..1752c0748 100644 --- a/src/FootnoteMarkFormatter.php +++ b/src/FootnoteMarkFormatter.php @@ -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, diff --git a/src/ReferenceMessageLocalizer.php b/src/ReferenceMessageLocalizer.php index 766baa60f..6ad1a2509 100644 --- a/src/ReferenceMessageLocalizer.php +++ b/src/ReferenceMessageLocalizer.php @@ -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; } diff --git a/src/ReferenceStack.php b/src/ReferenceStack.php index bbb0d8892..db6b3c83a 100644 --- a/src/ReferenceStack.php +++ b/src/ReferenceStack.php @@ -43,25 +43,20 @@ class ReferenceStack { * * @var array[][] */ - private $refs = []; + private array $refs = []; /** * Auto-incrementing sequence number for all , 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 = []; /** * call stack @@ -71,17 +66,13 @@ class ReferenceStack { * @var (array|false)[] * @phan-var array */ - 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; } diff --git a/src/ReferencesFormatter.php b/src/ReferencesFormatter.php index 99d120f9d..e1fe13ee8 100644 --- a/src/ReferencesFormatter.php +++ b/src/ReferencesFormatter.php @@ -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, diff --git a/tests/phpunit/CiteIntegrationTest.php b/tests/phpunit/CiteIntegrationTest.php index 6fa057c57..12e9e7224 100644 --- a/tests/phpunit/CiteIntegrationTest.php +++ b/tests/phpunit/CiteIntegrationTest.php @@ -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( '' ); diff --git a/tests/phpunit/integration/CiteTest.php b/tests/phpunit/integration/CiteTest.php index baa7536e0..43f15ed63 100644 --- a/tests/phpunit/integration/CiteTest.php +++ b/tests/phpunit/integration/CiteTest.php @@ -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( '' ); @@ -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() {