From 5c93bbfd0083569da147e5b5f3eaaafdf386e489 Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Mon, 5 Jun 2023 16:36:03 +0200 Subject: [PATCH] Add strict types to all class properties A good bunch of PHPDoc comments is obsolete when we use strict types. Change-Id: Ie0692fae4d96c749e9048f7e7c6931ec97998093 --- src/AnchorFormatter.php | 8 +----- src/Cite.php | 38 ++++++-------------------- src/ErrorReporter.php | 14 ++-------- src/FootnoteMarkFormatter.php | 29 ++++---------------- src/ReferenceMessageLocalizer.php | 8 +----- src/ReferenceStack.php | 23 +++++----------- src/ReferencesFormatter.php | 23 ++-------------- tests/phpunit/CiteIntegrationTest.php | 5 ++-- tests/phpunit/integration/CiteTest.php | 14 +++++----- 9 files changed, 36 insertions(+), 126 deletions(-) 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 2aa2b3e77..16d17fd6f 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 3aa585201..8d89d896e 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 0bc430a68..8696cb0dd 100644 --- a/tests/phpunit/integration/CiteTest.php +++ b/tests/phpunit/integration/CiteTest.php @@ -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( '' ); @@ -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() {