Skip to content

Commit

Permalink
Merge "lib/packages: Fix implicit nullable types"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Dec 11, 2024
2 parents 4115aea + 114cd5c commit 759cd48
Show file tree
Hide file tree
Showing 22 changed files with 30 additions and 46 deletions.
1 change: 0 additions & 1 deletion .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
</rule>

<rule ref="MediaWiki.Usage.NullableType.ExplicitNullableTypes">
<exclude-pattern>lib/packages/</exclude-pattern>
<exclude-pattern>repo/</exclude-pattern>
</rule>

Expand Down
4 changes: 2 additions & 2 deletions lib/packages/wikibase/changes/src/EntityChangeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public function newFromFieldData( array $fields ): EntityChange {
*/
public function newFromUpdate(
$action,
EntityDocument $oldEntity = null,
EntityDocument $newEntity = null
?EntityDocument $oldEntity,
?EntityDocument $newEntity = null
): EntityChange {
if ( $oldEntity === null && $newEntity === null ) {
throw new InvalidArgumentException( 'Either $oldEntity or $newEntity must be given' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class EntityLookupException extends RuntimeException {
* @param string|null $message
* @param Exception|null $previous
*/
public function __construct( EntityId $entityId, $message = null, Exception $previous = null ) {
public function __construct( EntityId $entityId, $message = null, ?Exception $previous = null ) {
$this->entityId = $entityId;

parent::__construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class EntityRedirectLookupException extends RuntimeException {
* @param string|null $message
* @param Exception|null $previous
*/
public function __construct( EntityId $entityId, $message = null, Exception $previous = null ) {
public function __construct( EntityId $entityId, $message = null, ?Exception $previous = null ) {
$this->entityId = $entityId;

parent::__construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ItemLookupException extends EntityLookupException {
* @param string|null $message
* @param Exception|null $previous
*/
public function __construct( ItemId $itemId, $message = null, Exception $previous = null ) {
public function __construct( ItemId $itemId, $message = null, ?Exception $previous = null ) {
parent::__construct(
$itemId,
$message ?: 'Item lookup failed for: ' . $itemId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LabelDescriptionLookupException extends RuntimeException {
* @param string|null $message
* @param Exception|null $previous
*/
public function __construct( EntityId $entityId, $message = null, Exception $previous = null ) {
public function __construct( EntityId $entityId, $message = null, ?Exception $previous = null ) {
$this->entityId = $entityId;

parent::__construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
array $toIds,
$maxDepth,
$message = null,
Exception $previous = null
?Exception $previous = null
) {
$this->maxDepth = $maxDepth;
$message = $message ?: 'Referenced entity id lookup failed: Maximum depth of ' . $maxDepth . ' exhausted.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
array $toIds,
$maxEntityVisits,
$message = null,
Exception $previous = null
?Exception $previous = null
) {
$this->maxEntityVisits = $maxEntityVisits;
$message = $message ?: 'Referenced entity id lookup failed: Maximum number of entity visits (' .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PropertyDataTypeLookupException extends RuntimeException {
* @param string|null $message
* @param Exception|null $previous
*/
public function __construct( PropertyId $propertyId, $message = null, Exception $previous = null ) {
public function __construct( PropertyId $propertyId, $message = null, ?Exception $previous = null ) {
$this->propertyId = $propertyId;

parent::__construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PropertyLookupException extends EntityLookupException {
* @param string|null $message
* @param Exception|null $previous
*/
public function __construct( PropertyId $propertyId, $message = null, Exception $previous = null ) {
public function __construct( PropertyId $propertyId, $message = null, ?Exception $previous = null ) {
parent::__construct(
$propertyId,
$message ?: 'Property lookup failed for: ' . $propertyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
PropertyId $propertyId,
array $toIds,
$message = null,
Exception $previous = null
?Exception $previous = null
) {
$this->fromId = $fromId;
$this->propertyId = $propertyId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
EntityId $entityId,
array $languageCodes,
$message = null,
Exception $previous = null
?Exception $previous = null
) {
$this->entityId = $entityId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class UnknownForeignRepositoryException extends InvalidArgumentException {
* @param string|null $message
* @param Exception|null $previous
*/
public function __construct( $repositoryName, $message = null, Exception $previous = null ) {
public function __construct( $repositoryName, $message = null, ?Exception $previous = null ) {
$this->repositoryName = $repositoryName;

parent::__construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
EntityId $entityId,
EntityId $redirectTargetId,
$message = null,
Exception $previous = null
?Exception $previous = null
) {
$defaultMessage = 'Unresolved redirect from ' . $entityId->getSerialization() . ' to '
. $redirectTargetId->getSerialization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FakeEntityDocument implements EntityDocument {
*/
private $id;

public function __construct( EntityId $id = null ) {
public function __construct( ?EntityId $id = null ) {
$this->id = $id;
}

Expand Down
13 changes: 4 additions & 9 deletions lib/packages/wikibase/data-model/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 lib/packages/wikibase/data-model/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 lib/packages/wikibase/data-model/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
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
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 lib/packages/wikibase/data-model/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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(
Deserializer $dataValueDeserializer,
EntityIdParser $idParser,
CurrentDeserializerFactory $currentFactory,
DispatchableDeserializer $currentEntityDeserializer = null
?DispatchableDeserializer $currentEntityDeserializer = null
) {
$this->legacyFactory = new LegacyDeserializerFactory( $dataValueDeserializer, $idParser );
$this->currentFactory = $currentFactory;
Expand Down

0 comments on commit 759cd48

Please sign in to comment.