Skip to content

Commit

Permalink
lib/packages: Fix implicit nullable types
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lucaswerkmeister authored and WMDE bot committed Dec 11, 2024
1 parent b83b175 commit 97319c3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 29 deletions.
13 changes: 4 additions & 9 deletions src/Entity/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,12 @@ class Item implements

/**
* @since 1.0
*
* @param ItemId|null $id
* @param Fingerprint|null $fingerprint
* @param SiteLinkList|null $siteLinks
* @param StatementList|null $statements
*/
public function __construct(
ItemId $id = null,
Fingerprint $fingerprint = null,
SiteLinkList $siteLinks = null,
StatementList $statements = null
?ItemId $id = null,
?Fingerprint $fingerprint = null,
?SiteLinkList $siteLinks = null,
?StatementList $statements = null
) {
$this->id = $id;
$this->fingerprint = $fingerprint ?: new Fingerprint();
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct(
?PropertyId $id,
?Fingerprint $fingerprint,
$dataTypeId,
StatementList $statements = null
?StatementList $statements = null
) {
$this->id = $id;
$this->fingerprint = $fingerprint ?: new Fingerprint();
Expand Down
11 changes: 3 additions & 8 deletions src/Statement/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,12 @@ class Statement implements PropertyIdProvider {

/**
* @since 2.0
*
* @param Snak $mainSnak
* @param SnakList|null $qualifiers
* @param ReferenceList|null $references
* @param string|null $guid
*/
public function __construct(
Snak $mainSnak,
SnakList $qualifiers = null,
ReferenceList $references = null,
string $guid = null
?SnakList $qualifiers = null,
?ReferenceList $references = null,
?string $guid = null
) {
$this->mainSnak = $mainSnak;
$this->qualifiers = $qualifiers ?: new SnakList();
Expand Down
2 changes: 1 addition & 1 deletion src/Statement/StatementGuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class StatementGuid {
* @param string|null $originalStatementId the original, non-normalized, statement id.
* Defaults to `null` for compatability.
*/
public function __construct( EntityId $entityId, string $guidPart, string $originalStatementId = null ) {
public function __construct( EntityId $entityId, string $guidPart, ?string $originalStatementId = null ) {
$constructedStatementId = $entityId->getSerialization() . self::SEPARATOR . $guidPart;
if ( $originalStatementId !== null
&& strtolower( $originalStatementId ) !== strtolower( $constructedStatementId ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/Statement/StatementList.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getPropertyIds(): array {
*
* @throws InvalidArgumentException
*/
public function addStatement( Statement $statement, int $index = null ): void {
public function addStatement( Statement $statement, ?int $index = null ): void {
if ( $index === null ) {
$this->statements[] = $statement;
} elseif ( $index >= 0 ) {
Expand All @@ -87,7 +87,7 @@ public function addStatement( Statement $statement, int $index = null ): void {
* @param string|null $guid
*/
public function addNewStatement(
Snak $mainSnak, $qualifiers = null, $references = null, string $guid = null
Snak $mainSnak, $qualifiers = null, $references = null, ?string $guid = null
): void {
$qualifiers = is_array( $qualifiers ) ? new SnakList( $qualifiers ) : $qualifiers;
$references = is_array( $references ) ? new ReferenceList( $references ) : $references;
Expand Down
11 changes: 3 additions & 8 deletions src/Term/Fingerprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ public static function newEmpty() {
*/
private $aliasGroups;

/**
* @param TermList|null $labels
* @param TermList|null $descriptions
* @param AliasGroupList|null $aliasGroups
*/
public function __construct(
TermList $labels = null,
TermList $descriptions = null,
AliasGroupList $aliasGroups = null
?TermList $labels = null,
?TermList $descriptions = null,
?AliasGroupList $aliasGroups = null
) {
$this->labels = $labels ?: new TermList();
$this->descriptions = $descriptions ?: new TermList();
Expand Down

0 comments on commit 97319c3

Please sign in to comment.