jenkins-bot has submitted this change and it was merged.

Change subject: Reduce NPath complexity in ReferencedUrlFinder
......................................................................


Reduce NPath complexity in ReferencedUrlFinder

Also got rid of pointless catch of OutOfBoundsException and a paranoid
check for a situation that should never occur.

Change-Id: I07b1d2b1e36f74c62bcc0d532a464603afa32349
---
M lib/includes/ReferencedUrlFinder.php
1 file changed, 33 insertions(+), 29 deletions(-)

Approvals:
  Denny Vrandecic: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/includes/ReferencedUrlFinder.php 
b/lib/includes/ReferencedUrlFinder.php
index ef96a47..8a5e07e 100644
--- a/lib/includes/ReferencedUrlFinder.php
+++ b/lib/includes/ReferencedUrlFinder.php
@@ -3,7 +3,6 @@
 namespace Wikibase;
 
 use DataValues\StringValue;
-use OutOfBoundsException;
 use Wikibase\Lib\PropertyDataTypeLookup;
 use Wikibase\Lib\PropertyNotFoundException;
 
@@ -17,6 +16,7 @@
  *
  * @licence GNU GPL v2+
  * @author Daniel Kinzler
+ * @author Jeroen De Dauw < [email protected] >
  */
 class ReferencedUrlFinder {
 
@@ -26,6 +26,11 @@
         * @var PropertyDataTypeLookup
         */
        protected $propertyDataTypeLookup;
+
+       /**
+        * @var string[]
+        */
+       protected $foundURLs;
 
        /**
         * @since 0.4
@@ -42,41 +47,40 @@
         * @return string[]
         */
        public function findSnakLinks( array $snaks ) {
-               $foundURLs = array();
+               $this->foundURLs = array();
 
                foreach ( $snaks as $snak ) {
-                       // PropertyValueSnaks might have a value referencing a 
URL, find those:
                        if( $snak instanceof PropertyValueSnak ) {
-                               try {
-                                       $type = 
$this->propertyDataTypeLookup->getDataTypeIdForProperty( $snak->getPropertyId() 
);
-                               } catch ( OutOfBoundsException $ex ) {
-                                       wfLogWarning( 'No data type known for 
property ' . $snak->getPropertyId() );
-                                       continue;
-                               } catch ( PropertyNotFoundException $ex ) {
-                                       wfLogWarning( 'No data type known for 
unknown property ' . $snak->getPropertyId() );
-                                       continue;
-                               }
-                               
-                               if ( $type !== 'url' ) {
-                                       continue;
-                               }
-
-                               $snakValue = $snak->getDataValue();
-
-                               if( $snakValue === null ) {
-                                       // shouldn't ever run into this, but 
make sure!
-                                       continue;
-                               }
-
-                               if ( $snakValue instanceof StringValue ) {
-                                       $foundURLs[] = $snakValue->getValue();
-                               } else {
-                                       wfLogWarning( 'Unexpected value type 
for url: ' . $snakValue->getType() );
+                               if ( $this->isUrlProperty( 
$snak->getPropertyId() ) ) {
+                                       $this->findPropertyValueSnakLinks( 
$snak );
                                }
                        }
                }
 
-               return array_unique( $foundURLs );
+               return array_unique( $this->foundURLs );
+       }
+
+       protected function findPropertyValueSnakLinks( PropertyValueSnak $snak 
) {
+               $snakValue = $snak->getDataValue();
+
+               if ( $snakValue instanceof StringValue ) {
+                       $this->foundURLs[] = $snakValue->getValue();
+               } else {
+                       wfLogWarning( 'Unexpected value type for url: ' . 
$snakValue->getType() );
+               }
+       }
+
+       protected function isUrlProperty( EntityId $propertyId ) {
+               try {
+                       $type = 
$this->propertyDataTypeLookup->getDataTypeIdForProperty( $propertyId );
+               } catch ( PropertyNotFoundException $ex ) {
+                       // FIXME: wrong place to stop exception propagation.
+                       // Either do not catch this here or throw a new 
exception instead.
+                       wfLogWarning( 'No data type known for unknown property 
' . $propertyId );
+                       return false;
+               }
+
+               return $type === 'url';
        }
 
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I07b1d2b1e36f74c62bcc0d532a464603afa32349
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to