jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/399870 )
Change subject: Improve type safety in ConstraintCheck related code
......................................................................
Improve type safety in ConstraintCheck related code
This patch aims to improve the overall type safety in this component a
bit by adding missing PHPDoc blocks, and rearranging some code. This
does not fix all type safety warning, but improves the situation.
Change-Id: Id117a96bcf94df0637f886d135ddea0ffeae6201
---
M src/Api/CheckConstraints.php
M src/ConstraintCheck/Helper/ConnectionCheckerHelper.php
M src/ConstraintCheck/Helper/ConstraintParameterParser.php
M src/ConstraintCheck/ItemIdSnakValue.php
M src/UpdateConstraintsTableJob.php
5 files changed, 29 insertions(+), 17 deletions(-)
Approvals:
Lucas Werkmeister (WMDE): Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/Api/CheckConstraints.php b/src/Api/CheckConstraints.php
index bc4b96e..bcee76f 100644
--- a/src/Api/CheckConstraints.php
+++ b/src/Api/CheckConstraints.php
@@ -8,6 +8,7 @@
use MediaWiki\MediaWikiServices;
use RequestContext;
use ValueFormatters\FormatterOptions;
+use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\EntityIdParser;
use Wikibase\DataModel\Entity\EntityIdParsingException;
use Wikibase\DataModel\Services\Statement\StatementGuidValidator;
@@ -203,10 +204,7 @@
$this->getResult()->addValue(
null,
$this->getModuleName(),
- $this->resultsBuilder->getResults(
- $entityIds,
- $claimIds, $constraintIDs
- )->getArray()
+ $this->resultsBuilder->getResults( $entityIds,
$claimIds, $constraintIDs )->getArray()
);
// ensure that result contains the given entity IDs even if
they have no statements
foreach ( $entityIds as $entityId ) {
@@ -218,6 +216,11 @@
$this->resultBuilder->markSuccess( 1 );
}
+ /**
+ * @param array $params
+ *
+ * @return EntityId[]
+ */
private function parseEntityIds( array $params ) {
$ids = $params[self::PARAM_ID];
@@ -238,6 +241,11 @@
}, $ids );
}
+ /**
+ * @param array $params
+ *
+ * @return string[]
+ */
private function parseClaimIds( array $params ) {
$ids = $params[self::PARAM_CLAIM_ID];
diff --git a/src/ConstraintCheck/Helper/ConnectionCheckerHelper.php
b/src/ConstraintCheck/Helper/ConnectionCheckerHelper.php
index ffba31c..3cc47bf 100644
--- a/src/ConstraintCheck/Helper/ConnectionCheckerHelper.php
+++ b/src/ConstraintCheck/Helper/ConnectionCheckerHelper.php
@@ -3,7 +3,9 @@
namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Helper;
use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\EntityIdValue;
use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Statement\StatementList;
use WikibaseQuality\ConstraintReport\ConstraintCheck\ItemIdSnakValue;
@@ -54,10 +56,9 @@
/** @var Statement $statement */
foreach ( $statementListByPropertyId as $statement ) {
$snak = $statement->getMainSnak();
- if ( $snak->getType() === 'value' ) {
+ if ( $snak instanceof PropertyValueSnak ) {
$dataValue = $snak->getDataValue();
- if (
- $dataValue->getType() ===
'wikibase-entityid' &&
+ if ( $dataValue instanceof EntityIdValue &&
$dataValue->getEntityId()->equals(
$value )
) {
return $statement;
diff --git a/src/ConstraintCheck/Helper/ConstraintParameterParser.php
b/src/ConstraintCheck/Helper/ConstraintParameterParser.php
index 06ffb99..d9750e3 100644
--- a/src/ConstraintCheck/Helper/ConstraintParameterParser.php
+++ b/src/ConstraintCheck/Helper/ConstraintParameterParser.php
@@ -6,6 +6,7 @@
use DataValues\DataValue;
use DataValues\MonolingualTextValue;
use DataValues\StringValue;
+use DataValues\UnboundedQuantityValue;
use Language;
use Wikibase\DataModel\DeserializerFactory;
use Wikibase\DataModel\Deserializers\SnakDeserializer;
@@ -394,12 +395,12 @@
* @return bool
*/
private function exactlyOneQuantityWithUnit( DataValue $min = null,
DataValue $max = null, $unit ) {
- if ( $min === null || $max === null ) {
+ if ( !( $min instanceof UnboundedQuantityValue ) ||
+ !( $max instanceof UnboundedQuantityValue )
+ ) {
return false;
}
- if ( $min->getType() !== 'quantity' || $max->getType() !==
'quantity' ) {
- return false;
- }
+
return ( $min->getUnit() === $unit ) !== ( $max->getUnit() ===
$unit );
}
diff --git a/src/ConstraintCheck/ItemIdSnakValue.php
b/src/ConstraintCheck/ItemIdSnakValue.php
index 117dca7..977dbb1 100644
--- a/src/ConstraintCheck/ItemIdSnakValue.php
+++ b/src/ConstraintCheck/ItemIdSnakValue.php
@@ -83,19 +83,20 @@
public static function fromSnak( Snak $snak ) {
switch ( true ) {
case $snak instanceof PropertyValueSnak:
- if (
- $snak->getDataValue() instanceof
EntityIdValue &&
- $snak->getDataValue()->getEntityId()
instanceof ItemId
+ $dataValue = $snak->getDataValue();
+ if ( $dataValue instanceof EntityIdValue
+ && $dataValue->getEntityId() instanceof
ItemId
) {
- return self::fromItemId(
$snak->getDataValue()->getEntityId() );
- } else {
- throw new InvalidArgumentException(
'Snak must contain item ID value or be a somevalue / novalue snak' );
+ return self::fromItemId(
$dataValue->getEntityId() );
}
+ break;
case $snak instanceof PropertySomeValueSnak:
return self::someValue();
case $snak instanceof PropertyNoValueSnak:
return self::noValue();
}
+
+ throw new InvalidArgumentException( 'Snak must contain item ID
value or be a somevalue / novalue snak' );
}
/**
diff --git a/src/UpdateConstraintsTableJob.php
b/src/UpdateConstraintsTableJob.php
index 9b72cbf..73e8308 100644
--- a/src/UpdateConstraintsTableJob.php
+++ b/src/UpdateConstraintsTableJob.php
@@ -147,6 +147,7 @@
$propertyId = new PropertyId( $this->propertyId );
$this->constraintRepo->deleteForPropertyWhereConstraintIdIsStatementId(
$propertyId );
+ /** @var Property $property */
$property = $this->entityLookup->getEntity( $propertyId );
$this->importConstraintsForProperty(
$property,
--
To view, visit https://gerrit.wikimedia.org/r/399870
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id117a96bcf94df0637f886d135ddea0ffeae6201
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Thiemo Kreuz (WMDE) <[email protected]>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Kreuz (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits