Jeroen De Dauw has uploaded a new change for review.

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

Change subject: Code style imporvements in TypeCheckerHelper
......................................................................

Code style imporvements in TypeCheckerHelper

Change-Id: Id7f533bd8da945a114a8b1b3a439099deb9828bd
---
M includes/ConstraintCheck/Helper/TypeCheckerHelper.php
1 file changed, 20 insertions(+), 8 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
 refs/changes/40/229640/1

diff --git a/includes/ConstraintCheck/Helper/TypeCheckerHelper.php 
b/includes/ConstraintCheck/Helper/TypeCheckerHelper.php
index 4b5973f..572702f 100644
--- a/includes/ConstraintCheck/Helper/TypeCheckerHelper.php
+++ b/includes/ConstraintCheck/Helper/TypeCheckerHelper.php
@@ -2,10 +2,12 @@
 
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Helper;
 
+use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\PropertyId;
 use Wikibase\DataModel\Statement\StatementList;
+use Wikibase\DataModel\Statement\StatementListProvider;
 use Wikibase\Lib\Store\EntityLookup;
-
 
 /**
  * Class for helper functions for range checkers.
@@ -35,20 +37,26 @@
         * Due to cyclic dependencies, the checks stops after a certain
         * depth is reached
         *
+        * FIXME: the implementation here relies on the ID being passed being 
an ItemId.
+        * However, the callers can not provide a guarentee of this.
+        *
         * @param EntityId $comparativeClass
         * @param array $classesToCheck
         * @param int $depth
         *
         * @return bool
         */
-       public function isSubclassOf( $comparativeClass, $classesToCheck, 
$depth ) {
-               $compliance = null;
+       public function isSubclassOf( EntityId $comparativeClass, 
$classesToCheck, $depth ) {
+               /**
+                * @var Item $item
+                */
                $item = $this->entityLookup->getEntity( $comparativeClass );
-               if ( !$item ) {
-                       return false; // lookup failed, probably because item 
doesn't exist
+
+               if ( $item === null ) {
+                       return false;
                }
 
-               foreach ( $item->getStatements()->getByPropertyId( new 
PropertyId( self::subclassId ) ) as $statement ) {
+               foreach ( $this->getSubclassStatements( $item ) as $statement ) 
{
                        $mainSnak = $statement->getMainSnak();
 
                        if ( !( $this->hasCorrectType( $mainSnak ) ) ) {
@@ -65,8 +73,7 @@
                                return false;
                        }
 
-                       $compliance = $this->isSubclassOf( $comparativeClass, 
$classesToCheck, $depth + 1 );
-                       if ( $compliance === true ) {
+                       if ( $this->isSubclassOf( $comparativeClass, 
$classesToCheck, $depth + 1 ) ) {
                                return true;
                        }
 
@@ -74,6 +81,11 @@
                return false;
        }
 
+       private function getSubclassStatements( StatementListProvider 
$statementListProvider ) {
+               return $statementListProvider->getStatements()
+                       ->getByPropertyId( new PropertyId( self::subclassId ) 
)->toArray();
+       }
+
        /**
         * Checks, if one of the itemId serializations in $classesToCheck
         * is contained in the list of $statements

-- 
To view, visit https://gerrit.wikimedia.org/r/229640
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id7f533bd8da945a114a8b1b3a439099deb9828bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to