Skip to content

Commit 84de428

Browse files
coddersWMDE bot
authored andcommitted
Re-enable Phan and fix warnings / errors for `data-model/src'
Some directories are excluded from Phan checks as a result of T289040. .phan/config.php includes the folders for the libraries in exclude_analysis_directory_list. Enabling Phan checks results in a build failure. Resolve the Phan warnings and re-enable checks for the `data-model/src` folder. Bug: T353623 Change-Id: Ie7ec30e95f027361efcbfb5c22510f1261c61de1
1 parent 7029507 commit 84de428

15 files changed

+44
-32
lines changed

src/ByPropertyIdArray.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ private function movePropertyGroup( PropertyId $propertyId, $toIndex ) {
307307

308308
$oldIndex = $this->getPropertyGroupIndex( $propertyId );
309309
$byIdClone = $this->byId;
310+
if ( $byIdClone === null ) {
311+
throw new RuntimeException( 'LogicError - index should have been built' );
312+
}
310313

311314
// Remove "property group" to calculate the groups new index:
312315
unset( $this->byId[$propertyId->getSerialization()] );
@@ -432,7 +435,7 @@ public function addObjectAtIndex( $object, $index = null ) {
432435
if ( count( $this ) === 0 ) {
433436
// Array is empty, just append object.
434437
$this->append( $object );
435-
} elseif ( empty( $validIndices ) ) {
438+
} elseif ( $validIndices === [] ) {
436439
// No objects featuring that property exist. The object may be inserted at a place
437440
// between existing "property groups".
438441
$this->append( $object );
@@ -461,7 +464,7 @@ private function addObjectToPropertyGroup( $object, $index = null ) {
461464
$propertyId = $object->getPropertyId();
462465
$validIndices = $this->getFlatArrayIndices( $propertyId );
463466

464-
if ( empty( $validIndices ) ) {
467+
if ( $validIndices === [] ) {
465468
throw new OutOfBoundsException( 'No objects featuring the object\'s property exist' );
466469
}
467470

@@ -473,6 +476,10 @@ private function addObjectToPropertyGroup( $object, $index = null ) {
473476
$index = end( $validIndices );
474477
}
475478

479+
if ( $this->byId === null ) {
480+
throw new RuntimeException( 'LogicError - index should have been built' );
481+
}
482+
476483
if ( in_array( $index, $validIndices ) ) {
477484
// Add object at index within "property group".
478485
$this->byId[$propertyId->getSerialization()][] = $object;

src/Entity/BasicEntityIdParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct() {
2121
/**
2222
* @param string $idSerialization
2323
*
24-
* @return ItemId|PropertyId
24+
* @return EntityId
2525
* @throws EntityIdParsingException
2626
*/
2727
public function parse( $idSerialization ) {

src/Entity/Item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function getId() {
8787
/**
8888
* @since 0.5, can be null since 1.0
8989
*
90-
* @param ItemId|null $id
90+
* @param EntityId|null $id
9191
*
9292
* @throws InvalidArgumentException
9393
*/

src/Entity/ItemIdSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function count(): int {
5151
/**
5252
* @see IteratorAggregate::getIterator
5353
*
54-
* @return Iterator|ItemId[]
54+
* @return Traversable<ItemId>
5555
*/
5656
public function getIterator(): Traversable {
5757
return new ArrayIterator( $this->ids );

src/Entity/Property.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getId() {
9090
/**
9191
* @since 0.5, can be null since 1.0
9292
*
93-
* @param PropertyId|null $id
93+
* @param EntityId|null $id
9494
*
9595
* @throws InvalidArgumentException
9696
*/

src/Internal/MapValueHasher.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use InvalidArgumentException;
66
use Traversable;
7+
use Wikibase\DataModel\Reference;
78

89
/**
910
* Generates hashes for associative arrays based on the values of their elements.
@@ -27,14 +28,14 @@ public function __construct( $holdOrderIntoAccount = false ) {
2728
*
2829
* @since 0.1
2930
*
30-
* @param Traversable $map
31+
* @param Traversable|Reference[] $map
3132
*
3233
* @return string
3334
* @throws InvalidArgumentException
3435
*/
3536
public function hash( $map ) {
3637
if ( !is_iterable( $map ) ) {
37-
throw new InvalidArgumentException( '$map must be an array or an instance of Traversable' );
38+
throw new InvalidArgumentException( '$map must be a Reference array or an instance of Traversable' );
3839
}
3940

4041
$hashes = [];

src/ReferenceList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function unserialize( $serialized ) {
269269
* @return bool
270270
*/
271271
public function isEmpty() {
272-
return empty( $this->references );
272+
return $this->references === [];
273273
}
274274

275275
/**
@@ -316,7 +316,7 @@ public function count(): int {
316316
*
317317
* @since 5.0
318318
*
319-
* @return Iterator|Reference[]
319+
* @return Traversable<Reference>
320320
*/
321321
public function getIterator(): Traversable {
322322
return new ArrayIterator( array_values( $this->references ) );

src/SiteLinkList.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use ArrayIterator;
66
use Countable;
77
use InvalidArgumentException;
8-
use Iterator;
98
use IteratorAggregate;
109
use OutOfBoundsException;
1110
use Traversable;
@@ -103,7 +102,7 @@ public function setNewSiteLink( $siteId, $pageName, $badges = null ) {
103102
*
104103
* Returns an Iterator of SiteLink in which the keys are the site ids.
105104
*
106-
* @return Iterator|SiteLink[]
105+
* @return Traversable<SiteLink>
107106
*/
108107
public function getIterator(): Traversable {
109108
return new ArrayIterator( $this->siteLinks );
@@ -172,7 +171,7 @@ public function equals( $target ) {
172171
* @return bool
173172
*/
174173
public function isEmpty() {
175-
return empty( $this->siteLinks );
174+
return $this->siteLinks === [];
176175
}
177176

178177
/**

src/Snak/PropertyValueSnak.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ private function getDataValueSerializationForHash(): string {
7272
if ( method_exists( $this->dataValue, 'getSerializationForHash' ) ) {
7373
// If our DataValue provides/ needs a special serialization for
7474
// hashing, use it (currently only EntityIdValue).
75+
// @phan-suppress-next-line PhanUndeclaredMethod
7576
return $this->dataValue->getSerializationForHash();
76-
} else {
77-
$innerSerialization = $this->dataValue->serialize();
7877
}
78+
$innerSerialization = $this->dataValue->serialize();
7979
$className = get_class( $this->dataValue );
8080

8181
return 'C:' . strlen( $className ) . ':"' . $className .
82-
'":' . strlen( $innerSerialization ) . ':{' . $innerSerialization . '}';
82+
'":' . strlen( $innerSerialization ?? '' ) . ':{' . $innerSerialization . '}';
8383
}
8484

8585
/**

src/Snak/SnakList.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ public function offsetSet( $index, $value ): void {
241241
* all common code needed for set operations, including
242242
* type checking and offset resolving.
243243
*
244-
* @param int|string $index
244+
* If null is supplied as an index, the next new offset
245+
* will be assigned.
246+
*
247+
* @param int|string|null $index
245248
* @param Snak $value
246249
*
247250
* @throws InvalidArgumentException

0 commit comments

Comments
 (0)