Skip to content

Commit 97319c3

Browse files
lucaswerkmeisterWMDE bot
authored andcommitted
lib/packages: Fix implicit nullable types
In EntityChangeFactory::newFromUpdate(), I initially wanted to make both EntityDocument arguments required, but Phan and the tests showed that WikiPageActionEntityChangeFactory::newForPageDeleted() actually calls it without the last argument, so let’s leave the last default argument in place. (Making both EntityDocument arguments optional doesn’t really make sense because at least one has to be non-null according to the condition immediately below the method signature – although I could also be convinced that having only one of the parameters optional is weird and inconsistent and it would be nicer to make them both optional after all, if anyone feels that way.) Bug: T379509 Change-Id: I7840b2c1af4424effbb774b42c02813c73f113a7
1 parent b83b175 commit 97319c3

6 files changed

Lines changed: 14 additions & 29 deletions

File tree

src/Entity/Item.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,12 @@ class Item implements
6060

6161
/**
6262
* @since 1.0
63-
*
64-
* @param ItemId|null $id
65-
* @param Fingerprint|null $fingerprint
66-
* @param SiteLinkList|null $siteLinks
67-
* @param StatementList|null $statements
6863
*/
6964
public function __construct(
70-
ItemId $id = null,
71-
Fingerprint $fingerprint = null,
72-
SiteLinkList $siteLinks = null,
73-
StatementList $statements = null
65+
?ItemId $id = null,
66+
?Fingerprint $fingerprint = null,
67+
?SiteLinkList $siteLinks = null,
68+
?StatementList $statements = null
7469
) {
7570
$this->id = $id;
7671
$this->fingerprint = $fingerprint ?: new Fingerprint();

src/Entity/Property.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function __construct(
6868
?PropertyId $id,
6969
?Fingerprint $fingerprint,
7070
$dataTypeId,
71-
StatementList $statements = null
71+
?StatementList $statements = null
7272
) {
7373
$this->id = $id;
7474
$this->fingerprint = $fingerprint ?: new Fingerprint();

src/Statement/Statement.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,12 @@ class Statement implements PropertyIdProvider {
5959

6060
/**
6161
* @since 2.0
62-
*
63-
* @param Snak $mainSnak
64-
* @param SnakList|null $qualifiers
65-
* @param ReferenceList|null $references
66-
* @param string|null $guid
6762
*/
6863
public function __construct(
6964
Snak $mainSnak,
70-
SnakList $qualifiers = null,
71-
ReferenceList $references = null,
72-
string $guid = null
65+
?SnakList $qualifiers = null,
66+
?ReferenceList $references = null,
67+
?string $guid = null
7368
) {
7469
$this->mainSnak = $mainSnak;
7570
$this->qualifiers = $qualifiers ?: new SnakList();

src/Statement/StatementGuid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class StatementGuid {
3232
* @param string|null $originalStatementId the original, non-normalized, statement id.
3333
* Defaults to `null` for compatability.
3434
*/
35-
public function __construct( EntityId $entityId, string $guidPart, string $originalStatementId = null ) {
35+
public function __construct( EntityId $entityId, string $guidPart, ?string $originalStatementId = null ) {
3636
$constructedStatementId = $entityId->getSerialization() . self::SEPARATOR . $guidPart;
3737
if ( $originalStatementId !== null
3838
&& strtolower( $originalStatementId ) !== strtolower( $constructedStatementId ) ) {

src/Statement/StatementList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function getPropertyIds(): array {
7070
*
7171
* @throws InvalidArgumentException
7272
*/
73-
public function addStatement( Statement $statement, int $index = null ): void {
73+
public function addStatement( Statement $statement, ?int $index = null ): void {
7474
if ( $index === null ) {
7575
$this->statements[] = $statement;
7676
} elseif ( $index >= 0 ) {
@@ -87,7 +87,7 @@ public function addStatement( Statement $statement, int $index = null ): void {
8787
* @param string|null $guid
8888
*/
8989
public function addNewStatement(
90-
Snak $mainSnak, $qualifiers = null, $references = null, string $guid = null
90+
Snak $mainSnak, $qualifiers = null, $references = null, ?string $guid = null
9191
): void {
9292
$qualifiers = is_array( $qualifiers ) ? new SnakList( $qualifiers ) : $qualifiers;
9393
$references = is_array( $references ) ? new ReferenceList( $references ) : $references;

src/Term/Fingerprint.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,10 @@ public static function newEmpty() {
4242
*/
4343
private $aliasGroups;
4444

45-
/**
46-
* @param TermList|null $labels
47-
* @param TermList|null $descriptions
48-
* @param AliasGroupList|null $aliasGroups
49-
*/
5045
public function __construct(
51-
TermList $labels = null,
52-
TermList $descriptions = null,
53-
AliasGroupList $aliasGroups = null
46+
?TermList $labels = null,
47+
?TermList $descriptions = null,
48+
?AliasGroupList $aliasGroups = null
5449
) {
5550
$this->labels = $labels ?: new TermList();
5651
$this->descriptions = $descriptions ?: new TermList();

0 commit comments

Comments
 (0)