Page MenuHomePhabricator

WikibaseQualityConstraints Phan CI broken by nullable type of Statement::getGuid()
Closed, ResolvedPublic3 Estimated Story Points

Description

Problem:

DM: Add type hints to Statement added the return type ?string to Statement::getGuid(), which breaks Phan in WikibaseQualityConstraints (build):

src/ConstraintCheck/Context/MainSnakContext.php:170 PhanTypeMismatchArgumentNullable Argument 3 ($statementGuid) is $this->statement->getGuid() of type ?string but \WikibaseQuality\ConstraintReport\ConstraintCheck\Context\MainSnakContextCursor::__construct() takes string defined at src/ConstraintCheck/Context/MainSnakContextCursor.php:36 (expected type to be non-nullable)
src/ConstraintCheck/Context/QualifierContext.php:43 PhanTypeMismatchArgumentNullable Argument 3 ($statementGuid) is $this->statement->getGuid() of type ?string but \WikibaseQuality\ConstraintReport\ConstraintCheck\Context\QualifierContextCursor::__construct() takes string defined at src/ConstraintCheck/Context/QualifierContextCursor.php:42 (expected type to be non-nullable)
src/ConstraintCheck/Context/ReferenceContext.php:51 PhanTypeMismatchArgumentNullable Argument 3 ($statementGuid) is $this->statement->getGuid() of type ?string but \WikibaseQuality\ConstraintReport\ConstraintCheck\Context\ReferenceContextCursor::__construct() takes string defined at src/ConstraintCheck/Context/ReferenceContextCursor.php:48 (expected type to be non-nullable)
src/ConstraintCheck/Helper/SparqlHelper.php:370 PhanTypeMismatchArgumentNullableInternal Argument 3 ($subject) is $statement->getGuid() of type ?string but \str_replace() takes array|string (expected type to be non-nullable)
src/Job/UpdateConstraintsTableJob.php:156 PhanTypeMismatchArgumentNullable Argument 1 ($constraintId) is $constraintId of type ?string but \WikibaseQuality\ConstraintReport\Constraint::__construct() takes string defined at src/Constraint.php:40 (expected type to be non-nullable)

Possible Solutions:

  • In order not to revert work done in DataModel in Wikibase.git, we should simply cast to non-nullable string particularly for Phan, both in WikibaseQualityConstraints, and in MediaInfo

Acceptance Criteria:

  • CI in WikibaseQualityConstraints is unblocked
  • CI in MediaInfo is unblocked

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Prio Notes

  • Affects end users / production (blocks CI)
  • Affects Development efforts
  • Does not affect onboarding efforts
  • Affects external stakeholders

WikibaseMediaInfo also seems to be affected (console for change):

src/WikibaseMediaInfoHooks.php:839 PhanTypeMismatchArgumentNullable Argument 1 ($serialization) is $statement->getGuid() of type ?string but \Wikibase\DataModel\Services\Statement\StatementGuidParser::parse() takes string defined at ../../extensions/Wikibase/lib/packages/wikibase/data-model-services/src/Statement/StatementGuidParser.php:37 (expected type to be non-nullable)

The fixes for this will probably take the form of extracting $guid variables and annotating them for Phan, something like:

'@phan-var string $guid'; // we know the statement has a GUID

(You can grep/codesearch for phan-var to find similar casts.)

Change 838173 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/WikibaseQualityConstraints@master] Fix Phan after getGuid() return type change

https://gerrit.wikimedia.org/r/838173

Change 838760 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/WikibaseMediaInfo@master] Fix Phan after getGuid() return type change

https://gerrit.wikimedia.org/r/838760

Change 838760 merged by jenkins-bot:

[mediawiki/extensions/WikibaseMediaInfo@master] Fix Phan after getGuid() return type change

https://gerrit.wikimedia.org/r/838760

Change 838173 merged by jenkins-bot:

[mediawiki/extensions/WikibaseQualityConstraints@master] Fix Phan after getGuid() return type change

https://gerrit.wikimedia.org/r/838173