mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-23 16:06:53 +00:00
Use type hints for properties, remove PHPCS overrides
MediaWiki's PHPCS plugin requires documentation comments on all properties, unless those properties are typed. This has potential to introduce bugs – in particular, because typed properties without a default value will throw an exception if their value is accessed before it's defined, while previously they defaulted to null. I fixed this when I found it (making them nullable and null by default), but I may have missed some cases. Change-Id: If5b1f4d542ce3e1b69327ee4283f7c3e133a62a0
This commit is contained in:
parent
0312df9e72
commit
781a33357b
|
@ -1,10 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset>
|
||||
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
|
||||
<!-- Do not require redundant documentation comments, we mostly use type hints -->
|
||||
<exclude name="MediaWiki.Commenting.PropertyDocumentation.MissingDocumentationPrivate" />
|
||||
<exclude name="MediaWiki.Commenting.PropertyDocumentation.MissingDocumentationProtected" />
|
||||
<exclude name="MediaWiki.Commenting.PropertyDocumentation.MissingDocumentationPublic" />
|
||||
<exclude name="MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures" />
|
||||
</rule>
|
||||
<file>.</file>
|
||||
|
|
|
@ -40,13 +40,16 @@ class CommentParser {
|
|||
private LanguageConverterFactory $languageConverterFactory;
|
||||
private TitleParser $titleParser;
|
||||
|
||||
private $dateFormat;
|
||||
private $digits;
|
||||
/** @var string[] */
|
||||
private array $dateFormat;
|
||||
/** @var string[][] */
|
||||
private array $digits;
|
||||
/** @var string[][] */
|
||||
private $contLangMessages;
|
||||
private $localTimezone;
|
||||
private $timezones;
|
||||
private $specialContributionsName;
|
||||
private string $localTimezone;
|
||||
/** @var string[][] */
|
||||
private array $timezones;
|
||||
private string $specialContributionsName;
|
||||
|
||||
private Element $rootNode;
|
||||
private TitleValue $title;
|
||||
|
|
|
@ -20,7 +20,7 @@ class CommentUtils {
|
|||
private function __construct() {
|
||||
}
|
||||
|
||||
private static $blockElementTypes = [
|
||||
private static array $blockElementTypes = [
|
||||
'div', 'p',
|
||||
// Tables
|
||||
'table', 'tbody', 'thead', 'tfoot', 'caption', 'th', 'tr', 'td',
|
||||
|
|
|
@ -30,11 +30,11 @@ use Wikimedia\Parsoid\DOM\Text;
|
|||
* @property int $startOffset
|
||||
*/
|
||||
class ImmutableRange {
|
||||
private $mCommonAncestorContainer;
|
||||
private $mEndContainer;
|
||||
private $mEndOffset;
|
||||
private $mStartContainer;
|
||||
private $mStartOffset;
|
||||
private ?Node $mCommonAncestorContainer = null;
|
||||
private Node $mEndContainer;
|
||||
private int $mEndOffset;
|
||||
private Node $mStartContainer;
|
||||
private int $mStartOffset;
|
||||
|
||||
/**
|
||||
* Find the common ancestor container of two nodes
|
||||
|
|
|
@ -35,9 +35,10 @@ class NodeFilter {
|
|||
public const SHOW_DOCUMENT_FRAGMENT = 0x400;
|
||||
public const SHOW_NOTATION = 0x800;
|
||||
|
||||
/** @var callable */
|
||||
public $filter;
|
||||
|
||||
private $active = false;
|
||||
private bool $active = false;
|
||||
|
||||
/**
|
||||
* See https://dom.spec.whatwg.org/#dom-nodefilter-acceptnode
|
||||
|
|
|
@ -72,7 +72,7 @@ class SpecialFindComment extends FormSpecialPage {
|
|||
$form->setSubmitTextMsg( 'discussiontools-findcomment-label-search' );
|
||||
}
|
||||
|
||||
private $idOrName;
|
||||
private string $idOrName;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
|
|
|
@ -9,12 +9,12 @@ use MediaWiki\User\UserIdentity;
|
|||
* Representation of a subscription to a given topic.
|
||||
*/
|
||||
class SubscriptionItem {
|
||||
private $itemName;
|
||||
private $linkTarget;
|
||||
private $user;
|
||||
private $state;
|
||||
private $createdTimestamp;
|
||||
private $notifiedTimestamp;
|
||||
private UserIdentity $user;
|
||||
private string $itemName;
|
||||
private LinkTarget $linkTarget;
|
||||
private int $state;
|
||||
private ?string $createdTimestamp;
|
||||
private ?string $notifiedTimestamp;
|
||||
|
||||
/**
|
||||
* @param UserIdentity $user
|
||||
|
@ -28,7 +28,7 @@ class SubscriptionItem {
|
|||
public function __construct(
|
||||
UserIdentity $user,
|
||||
string $itemName,
|
||||
linkTarget $linkTarget,
|
||||
LinkTarget $linkTarget,
|
||||
int $state,
|
||||
?string $createdTimestamp,
|
||||
?string $notifiedTimestamp
|
||||
|
|
|
@ -21,11 +21,13 @@ class ContentCommentItem extends ContentThreadItem implements CommentItem {
|
|||
jsonSerialize as protected traitJsonSerialize;
|
||||
}
|
||||
|
||||
private $signatureRanges;
|
||||
private $timestampRanges;
|
||||
private $timestamp;
|
||||
private $author;
|
||||
private $displayName;
|
||||
/** @var ImmutableRange[] */
|
||||
private array $signatureRanges;
|
||||
/** @var ImmutableRange[] */
|
||||
private array $timestampRanges;
|
||||
private DateTimeImmutable $timestamp;
|
||||
private string $author;
|
||||
private ?string $displayName;
|
||||
|
||||
/**
|
||||
* @param int $level
|
||||
|
|
|
@ -19,21 +19,24 @@ use Wikimedia\Parsoid\Utils\DOMUtils;
|
|||
abstract class ContentThreadItem implements JsonSerializable, ThreadItem {
|
||||
use ThreadItemTrait;
|
||||
|
||||
protected $type;
|
||||
protected $range;
|
||||
protected $rootNode;
|
||||
protected $level;
|
||||
protected $parent;
|
||||
protected $warnings = [];
|
||||
protected string $type;
|
||||
protected ImmutableRange $range;
|
||||
protected Element $rootNode;
|
||||
protected int $level;
|
||||
protected ?ContentThreadItem $parent = null;
|
||||
/** @var string[] */
|
||||
protected array $warnings = [];
|
||||
|
||||
protected $name = null;
|
||||
protected $id = null;
|
||||
protected $replies = [];
|
||||
protected string $name;
|
||||
protected string $id;
|
||||
/** @var ContentThreadItem[] */
|
||||
protected array $replies = [];
|
||||
|
||||
protected $authors = null;
|
||||
protected $commentCount;
|
||||
protected $oldestReply;
|
||||
protected $latestReply;
|
||||
/** @var ?array[] */
|
||||
protected ?array $authors = null;
|
||||
protected int $commentCount;
|
||||
protected ?ContentCommentItem $oldestReply;
|
||||
protected ?ContentCommentItem $latestReply;
|
||||
|
||||
/**
|
||||
* @param string $type `heading` or `comment`
|
||||
|
@ -487,16 +490,16 @@ abstract class ContentThreadItem implements JsonSerializable, ThreadItem {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string|null $name Thread item name
|
||||
* @param string $name Thread item name
|
||||
*/
|
||||
public function setName( ?string $name ): void {
|
||||
public function setName( string $name ): void {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id Thread ID
|
||||
* @param string $id Thread ID
|
||||
*/
|
||||
public function setId( ?string $id ): void {
|
||||
public function setId( string $id ): void {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,12 @@ use Wikimedia\Parsoid\DOM\Node;
|
|||
*/
|
||||
class TreeWalker {
|
||||
|
||||
public $root;
|
||||
public $whatToShow;
|
||||
public $currentNode;
|
||||
public Node $root;
|
||||
public int $whatToShow;
|
||||
public Node $currentNode;
|
||||
/** @var callable */
|
||||
public $filter;
|
||||
|
||||
private $isActive = false;
|
||||
private bool $isActive = false;
|
||||
|
||||
/**
|
||||
* See https://dom.spec.whatwg.org/#interface-treewalker
|
||||
|
|
Loading…
Reference in a new issue