@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | private $stringComparer; |
| 19 | 19 | |
| 20 | - public function __construct( StringComparer $stringComparer ) { |
|
| 20 | + public function __construct(StringComparer $stringComparer) { |
|
| 21 | 21 | $this->stringComparer = $stringComparer; |
| 22 | 22 | } |
| 23 | 23 | |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | * @throws InvalidArgumentException |
| 31 | 31 | * @return string One of the ComparisonResult::STATUS_... constants. |
| 32 | 32 | */ |
| 33 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
| 34 | - if ( !$this->canCompare( $value, $comparativeValue ) ) { |
|
| 35 | - throw new InvalidArgumentException( 'Given values can not be compared using this comparer.' ); |
|
| 33 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
| 34 | + if (!$this->canCompare($value, $comparativeValue)) { |
|
| 35 | + throw new InvalidArgumentException('Given values can not be compared using this comparer.'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - return $this->stringComparer->compare( $value->getValue(), $comparativeValue->getValue() ); |
|
| 38 | + return $this->stringComparer->compare($value->getValue(), $comparativeValue->getValue()); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param DataValue $comparativeValue |
| 46 | 46 | * @return bool |
| 47 | 47 | */ |
| 48 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
| 48 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
| 49 | 49 | return $value instanceof StringValue && $comparativeValue instanceof StringValue; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | private $stringComparer; |
| 29 | 29 | |
| 30 | - public function __construct( TermIndex $termIndex, StringComparer $stringComparer ) { |
|
| 30 | + public function __construct(TermIndex $termIndex, StringComparer $stringComparer) { |
|
| 31 | 31 | $this->termIndex = $termIndex; |
| 32 | 32 | $this->stringComparer = $stringComparer; |
| 33 | 33 | } |
@@ -40,9 +40,9 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return string|null One of the ComparisonResult::STATUS_... constants. |
| 42 | 42 | */ |
| 43 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
| 44 | - Assert::parameterType( EntityIdValue::class, $value, '$value' ); |
|
| 45 | - Assert::parameterType( MonolingualTextValue::class, $comparativeValue, '$comparativeValue' ); |
|
| 43 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
| 44 | + Assert::parameterType(EntityIdValue::class, $value, '$value'); |
|
| 45 | + Assert::parameterType(MonolingualTextValue::class, $comparativeValue, '$comparativeValue'); |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * @var EntityIdValue $value |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | $entityId = $value->getEntityId(); |
| 53 | 53 | $language = $comparativeValue->getLanguageCode(); |
| 54 | - $terms = $this->getTerms( $entityId, $language ); |
|
| 54 | + $terms = $this->getTerms($entityId, $language); |
|
| 55 | 55 | |
| 56 | - if ( $terms ) { |
|
| 57 | - return $this->stringComparer->compareWithArray( $comparativeValue->getText(), $terms ); |
|
| 56 | + if ($terms) { |
|
| 57 | + return $this->stringComparer->compareWithArray($comparativeValue->getText(), $terms); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return null; |
@@ -68,18 +68,18 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return array |
| 70 | 70 | */ |
| 71 | - private function getTerms( EntityId $entityId, $language ) { |
|
| 71 | + private function getTerms(EntityId $entityId, $language) { |
|
| 72 | 72 | $terms = $this->termIndex->getTermsOfEntity( |
| 73 | 73 | $entityId, |
| 74 | 74 | [ |
| 75 | 75 | TermIndexEntry::TYPE_LABEL, |
| 76 | 76 | TermIndexEntry::TYPE_ALIAS |
| 77 | 77 | ], |
| 78 | - [ $language ] |
|
| 78 | + [$language] |
|
| 79 | 79 | ); |
| 80 | 80 | |
| 81 | 81 | return array_map( |
| 82 | - function( TermIndexEntry $term ) { |
|
| 82 | + function(TermIndexEntry $term) { |
|
| 83 | 83 | return $term->getText(); |
| 84 | 84 | }, |
| 85 | 85 | $terms |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * @param DataValue $comparativeValue |
| 94 | 94 | * @return bool |
| 95 | 95 | */ |
| 96 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
| 96 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
| 97 | 97 | return $value instanceof EntityIdValue && $comparativeValue instanceof MonolingualTextValue; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | private $stringComparer; |
| 19 | 19 | |
| 20 | - public function __construct( StringComparer $stringComparer ) { |
|
| 20 | + public function __construct(StringComparer $stringComparer) { |
|
| 21 | 21 | $this->stringComparer = $stringComparer; |
| 22 | 22 | } |
| 23 | 23 | |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | * @throws InvalidArgumentException |
| 31 | 31 | * @return string|null One of the ComparisonResult::STATUS_... constants. |
| 32 | 32 | */ |
| 33 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
| 34 | - if ( !$this->canCompare( $value, $comparativeValue ) ) { |
|
| 35 | - throw new InvalidArgumentException( 'Given values can not be compared using this comparer.' ); |
|
| 33 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
| 34 | + if (!$this->canCompare($value, $comparativeValue)) { |
|
| 35 | + throw new InvalidArgumentException('Given values can not be compared using this comparer.'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | * @var MonolingualTextValue $comparativeValue |
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | - if ( $value->getLanguageCode() === $comparativeValue->getLanguageCode() ) { |
|
| 44 | - return $this->stringComparer->compare( $value->getText(), $comparativeValue->getText() ); |
|
| 43 | + if ($value->getLanguageCode() === $comparativeValue->getLanguageCode()) { |
|
| 44 | + return $this->stringComparer->compare($value->getText(), $comparativeValue->getText()); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | return null; |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param DataValue $comparativeValue |
| 55 | 55 | * @return bool |
| 56 | 56 | */ |
| 57 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
| 57 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
| 58 | 58 | return $value instanceof MonolingualTextValue && $comparativeValue instanceof MonolingualTextValue; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | private $stringComparer; |
| 20 | 20 | |
| 21 | - public function __construct( StringComparer $stringComparer ) { |
|
| 21 | + public function __construct(StringComparer $stringComparer) { |
|
| 22 | 22 | $this->stringComparer = $stringComparer; |
| 23 | 23 | } |
| 24 | 24 | |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | * @throws InvalidArgumentException |
| 32 | 32 | * @return string|null One of the ComparisonResult::STATUS_... constants. |
| 33 | 33 | */ |
| 34 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
| 35 | - if ( !$this->canCompare( $value, $comparativeValue ) ) { |
|
| 36 | - throw new InvalidArgumentException( 'Given values can not be compared using this comparer.' ); |
|
| 34 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
| 35 | + if (!$this->canCompare($value, $comparativeValue)) { |
|
| 36 | + throw new InvalidArgumentException('Given values can not be compared using this comparer.'); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -43,21 +43,21 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | $texts = $value->getTexts(); |
| 45 | 45 | $comparativeTexts = $comparativeValue->getTexts(); |
| 46 | - $commonLanguages = array_intersect( array_keys( $texts ), array_keys( $comparativeTexts ) ); |
|
| 46 | + $commonLanguages = array_intersect(array_keys($texts), array_keys($comparativeTexts)); |
|
| 47 | 47 | |
| 48 | - if ( $commonLanguages ) { |
|
| 48 | + if ($commonLanguages) { |
|
| 49 | 49 | $totalResult = ComparisonResult::STATUS_MISMATCH; |
| 50 | 50 | |
| 51 | - foreach ( $commonLanguages as $language ) { |
|
| 51 | + foreach ($commonLanguages as $language) { |
|
| 52 | 52 | $monolingualText = $texts[$language]; |
| 53 | 53 | $comparativeMonolingualText = $comparativeTexts[$language]; |
| 54 | 54 | |
| 55 | - $result = $this->stringComparer->compare( $monolingualText->getText(), $comparativeMonolingualText->getText() ); |
|
| 56 | - if ( $result !== ComparisonResult::STATUS_MISMATCH ) { |
|
| 55 | + $result = $this->stringComparer->compare($monolingualText->getText(), $comparativeMonolingualText->getText()); |
|
| 56 | + if ($result !== ComparisonResult::STATUS_MISMATCH) { |
|
| 57 | 57 | $totalResult = $result; |
| 58 | 58 | |
| 59 | 59 | // FIXME: This reports a partial match in a single language as a full match! |
| 60 | - if ( $result === ComparisonResult::STATUS_MATCH ) { |
|
| 60 | + if ($result === ComparisonResult::STATUS_MATCH) { |
|
| 61 | 61 | break; |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @param DataValue $comparativeValue |
| 77 | 77 | * @return bool |
| 78 | 78 | */ |
| 79 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
| 79 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
| 80 | 80 | return $value instanceof MultilingualTextValue && $comparativeValue instanceof MultilingualTextValue; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | private $stringNormalizer; |
| 24 | 24 | |
| 25 | - public function __construct( StringNormalizer $stringNormalizer ) { |
|
| 25 | + public function __construct(StringNormalizer $stringNormalizer) { |
|
| 26 | 26 | $this->stringNormalizer = $stringNormalizer; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | * @param string $comparativeValue |
| 34 | 34 | * @return string |
| 35 | 35 | */ |
| 36 | - public function compare( $value, $comparativeValue ) { |
|
| 37 | - Assert::parameterType( 'string', $value, '$value' ); |
|
| 38 | - Assert::parameterType( 'string', $comparativeValue, '$comparativeValue' ); |
|
| 36 | + public function compare($value, $comparativeValue) { |
|
| 37 | + Assert::parameterType('string', $value, '$value'); |
|
| 38 | + Assert::parameterType('string', $comparativeValue, '$comparativeValue'); |
|
| 39 | 39 | |
| 40 | - $value = $this->cleanDataString( $value ); |
|
| 41 | - $comparativeValue = $this->cleanDataString( $comparativeValue ); |
|
| 40 | + $value = $this->cleanDataString($value); |
|
| 41 | + $comparativeValue = $this->cleanDataString($comparativeValue); |
|
| 42 | 42 | |
| 43 | - if ( $value === $comparativeValue ) { |
|
| 43 | + if ($value === $comparativeValue) { |
|
| 44 | 44 | return ComparisonResult::STATUS_MATCH; |
| 45 | - } elseif ( $this->checkSimilarity( $value, $comparativeValue ) ) { |
|
| 45 | + } elseif ($this->checkSimilarity($value, $comparativeValue)) { |
|
| 46 | 46 | return ComparisonResult::STATUS_PARTIAL_MATCH; |
| 47 | 47 | } else { |
| 48 | 48 | return ComparisonResult::STATUS_MISMATCH; |
@@ -56,19 +56,19 @@ discard block |
||
| 56 | 56 | * @param array $comparativeValues |
| 57 | 57 | * @return string |
| 58 | 58 | */ |
| 59 | - public function compareWithArray( $value, array $comparativeValues ) { |
|
| 60 | - Assert::parameterType( 'string', $value, '$value' ); |
|
| 61 | - Assert::parameterElementType( 'string', $comparativeValues, '$comparativeValues' ); |
|
| 59 | + public function compareWithArray($value, array $comparativeValues) { |
|
| 60 | + Assert::parameterType('string', $value, '$value'); |
|
| 61 | + Assert::parameterElementType('string', $comparativeValues, '$comparativeValues'); |
|
| 62 | 62 | |
| 63 | - $value = $this->cleanDataString( $value ); |
|
| 64 | - $comparativeValues = $this->cleanDataArray( $comparativeValues ); |
|
| 63 | + $value = $this->cleanDataString($value); |
|
| 64 | + $comparativeValues = $this->cleanDataArray($comparativeValues); |
|
| 65 | 65 | |
| 66 | - if ( in_array( $value, $comparativeValues ) ) { |
|
| 66 | + if (in_array($value, $comparativeValues)) { |
|
| 67 | 67 | return ComparisonResult::STATUS_MATCH; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - foreach ( $comparativeValues as $comparativeValue ) { |
|
| 71 | - if ( $this->checkSimilarity( $comparativeValue, $value ) ) { |
|
| 70 | + foreach ($comparativeValues as $comparativeValue) { |
|
| 71 | + if ($this->checkSimilarity($comparativeValue, $value)) { |
|
| 72 | 72 | return ComparisonResult::STATUS_PARTIAL_MATCH; |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -83,11 +83,11 @@ discard block |
||
| 83 | 83 | * @param string $comparativeValue |
| 84 | 84 | * @return bool |
| 85 | 85 | */ |
| 86 | - private function checkSimilarity( $value, $comparativeValue ) { |
|
| 86 | + private function checkSimilarity($value, $comparativeValue) { |
|
| 87 | 87 | return |
| 88 | - $this->percentagePrefixSimilarity( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD || |
|
| 89 | - $this->percentageSuffixSimilarity( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD || |
|
| 90 | - $this->percentageLevenshteinDistance( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD; |
|
| 88 | + $this->percentagePrefixSimilarity($value, $comparativeValue) > self::SIMILARITY_THRESHOLD || |
|
| 89 | + $this->percentageSuffixSimilarity($value, $comparativeValue) > self::SIMILARITY_THRESHOLD || |
|
| 90 | + $this->percentageLevenshteinDistance($value, $comparativeValue) > self::SIMILARITY_THRESHOLD; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return string |
| 99 | 99 | */ |
| 100 | - private function cleanDataString( $value ) { |
|
| 101 | - $value = $this->stringNormalizer->trimToNFC( $value ); |
|
| 100 | + private function cleanDataString($value) { |
|
| 101 | + $value = $this->stringNormalizer->trimToNFC($value); |
|
| 102 | 102 | |
| 103 | - return mb_strtolower( $value ); |
|
| 103 | + return mb_strtolower($value); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @return array |
| 112 | 112 | */ |
| 113 | - private function cleanDataArray( array $array ) { |
|
| 113 | + private function cleanDataArray(array $array) { |
|
| 114 | 114 | |
| 115 | 115 | return array_map( |
| 116 | - [ $this, 'cleanDataString' ], |
|
| 116 | + [$this, 'cleanDataString'], |
|
| 117 | 117 | $array ); |
| 118 | 118 | } |
| 119 | 119 | |
@@ -125,19 +125,19 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | * @return float |
| 127 | 127 | */ |
| 128 | - private function percentagePrefixSimilarity( $value, $comparativeValue ) { |
|
| 128 | + private function percentagePrefixSimilarity($value, $comparativeValue) { |
|
| 129 | 129 | $prefixLength = 0; // common prefix length |
| 130 | - $localLength = strlen( $value ); |
|
| 131 | - $externalLength = strlen( $comparativeValue ); |
|
| 132 | - while ( $prefixLength < min( $localLength, $externalLength ) ) { |
|
| 130 | + $localLength = strlen($value); |
|
| 131 | + $externalLength = strlen($comparativeValue); |
|
| 132 | + while ($prefixLength < min($localLength, $externalLength)) { |
|
| 133 | 133 | $c = $value[$prefixLength]; |
| 134 | - if ( $externalLength > $prefixLength && $comparativeValue[$prefixLength] !== $c ) { |
|
| 134 | + if ($externalLength > $prefixLength && $comparativeValue[$prefixLength] !== $c) { |
|
| 135 | 135 | break; |
| 136 | 136 | } |
| 137 | 137 | $prefixLength++; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - return $prefixLength / max( $localLength, $externalLength ); |
|
| 140 | + return $prefixLength / max($localLength, $externalLength); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -148,19 +148,19 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return float |
| 150 | 150 | */ |
| 151 | - private function percentageSuffixSimilarity( $value, $comparativeValue ) { |
|
| 151 | + private function percentageSuffixSimilarity($value, $comparativeValue) { |
|
| 152 | 152 | $suffixLength = 0; // common suffix length |
| 153 | - $localLength = strlen( $value ); |
|
| 154 | - $externalLength = strlen( $comparativeValue ); |
|
| 155 | - while ( $suffixLength < min( $localLength, $externalLength ) ) { |
|
| 153 | + $localLength = strlen($value); |
|
| 154 | + $externalLength = strlen($comparativeValue); |
|
| 155 | + while ($suffixLength < min($localLength, $externalLength)) { |
|
| 156 | 156 | $c = $value[$localLength - 1 - $suffixLength]; |
| 157 | - if ( $externalLength > $suffixLength && $comparativeValue[$externalLength - 1 - $suffixLength] !== $c ) { |
|
| 157 | + if ($externalLength > $suffixLength && $comparativeValue[$externalLength - 1 - $suffixLength] !== $c) { |
|
| 158 | 158 | break; |
| 159 | 159 | } |
| 160 | 160 | $suffixLength++; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - return $suffixLength / max( $localLength, $externalLength ); |
|
| 163 | + return $suffixLength / max($localLength, $externalLength); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -171,9 +171,9 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return float |
| 173 | 173 | */ |
| 174 | - private function percentageLevenshteinDistance( $value, $comparativeValue ) { |
|
| 175 | - $distance = levenshtein( $value, $comparativeValue ); |
|
| 176 | - $percentage = 1.0 - $distance / max( strlen( $value ), strlen( $comparativeValue ) ); |
|
| 174 | + private function percentageLevenshteinDistance($value, $comparativeValue) { |
|
| 175 | + $distance = levenshtein($value, $comparativeValue); |
|
| 176 | + $percentage = 1.0 - $distance / max(strlen($value), strlen($comparativeValue)); |
|
| 177 | 177 | |
| 178 | 178 | return $percentage; |
| 179 | 179 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | private $stringNormalizer; |
| 23 | 23 | |
| 24 | - public function __construct( TermIndex $termIndex, StringNormalizer $stringNormalizer ) { |
|
| 24 | + public function __construct(TermIndex $termIndex, StringNormalizer $stringNormalizer) { |
|
| 25 | 25 | $this->termIndex = $termIndex; |
| 26 | 26 | $this->stringNormalizer = $stringNormalizer; |
| 27 | 27 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @return StringComparer |
| 64 | 64 | */ |
| 65 | 65 | private function newStringComparer() { |
| 66 | - return new StringComparer( $this->stringNormalizer ); |
|
| 66 | + return new StringComparer($this->stringNormalizer); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | private $stringNormalizer; |
| 20 | 20 | |
| 21 | - public function __construct( StringNormalizer $stringNormalizer ) { |
|
| 21 | + public function __construct(StringNormalizer $stringNormalizer) { |
|
| 22 | 22 | $this->stringNormalizer = $stringNormalizer; |
| 23 | 23 | } |
| 24 | 24 | |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @return StringValue |
| 31 | 31 | */ |
| 32 | - public function parse( $value ) { |
|
| 33 | - Assert::parameterType( 'string', $value, '$value' ); |
|
| 32 | + public function parse($value) { |
|
| 33 | + Assert::parameterType('string', $value, '$value'); |
|
| 34 | 34 | |
| 35 | - return new StringValue( $this->stringNormalizer->trimToNFC( $value ) ); |
|
| 35 | + return new StringValue($this->stringNormalizer->trimToNFC($value)); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | private $monolingualTextValueParser; |
| 19 | 19 | |
| 20 | - public function __construct( ValueParser $monolingualTextValueParser ) { |
|
| 20 | + public function __construct(ValueParser $monolingualTextValueParser) { |
|
| 21 | 21 | $this->monolingualTextValueParser = $monolingualTextValueParser; |
| 22 | 22 | } |
| 23 | 23 | |
@@ -28,11 +28,11 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return MultilingualTextValue |
| 30 | 30 | */ |
| 31 | - public function parse( $value ) { |
|
| 32 | - Assert::parameterType( 'string', $value, '$value' ); |
|
| 31 | + public function parse($value) { |
|
| 32 | + Assert::parameterType('string', $value, '$value'); |
|
| 33 | 33 | |
| 34 | 34 | return new MultilingualTextValue( |
| 35 | - [ $this->monolingualTextValueParser->parse( $value ) ] |
|
| 35 | + [$this->monolingualTextValueParser->parse($value)] |
|
| 36 | 36 | ); |
| 37 | 37 | } |
| 38 | 38 | |
@@ -28,18 +28,18 @@ discard block |
||
| 28 | 28 | * @return DumpMetaInformation[] |
| 29 | 29 | * @throws InvalidArgumentException |
| 30 | 30 | */ |
| 31 | - public function getWithIds( array $dumpIds ) { |
|
| 32 | - if ( $dumpIds === [] ) { |
|
| 31 | + public function getWithIds(array $dumpIds) { |
|
| 32 | + if ($dumpIds === []) { |
|
| 33 | 33 | return []; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - foreach ( $dumpIds as $dumpId ) { |
|
| 37 | - if ( !is_string( $dumpId ) ) { |
|
| 38 | - throw new InvalidArgumentException( '$dumpIds must contain only strings.' ); |
|
| 36 | + foreach ($dumpIds as $dumpId) { |
|
| 37 | + if (!is_string($dumpId)) { |
|
| 38 | + throw new InvalidArgumentException('$dumpIds must contain only strings.'); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - $db = wfGetDB( DB_REPLICA ); |
|
| 42 | + $db = wfGetDB(DB_REPLICA); |
|
| 43 | 43 | $result = $db->select( |
| 44 | 44 | [ |
| 45 | 45 | self::META_TABLE_NAME, |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | ] |
| 60 | 60 | ); |
| 61 | 61 | |
| 62 | - return $this->buildDumpMetaInformationFromResult( $result ); |
|
| 62 | + return $this->buildDumpMetaInformationFromResult($result); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -71,20 +71,20 @@ discard block |
||
| 71 | 71 | * @throws InvalidArgumentException |
| 72 | 72 | * @return DumpMetaInformation[] |
| 73 | 73 | */ |
| 74 | - public function getWithIdentifierProperties( array $identifierPropertyIds ) { |
|
| 75 | - if ( $identifierPropertyIds === [] ) { |
|
| 74 | + public function getWithIdentifierProperties(array $identifierPropertyIds) { |
|
| 75 | + if ($identifierPropertyIds === []) { |
|
| 76 | 76 | return []; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - foreach ( $identifierPropertyIds as $propertyId ) { |
|
| 80 | - if ( !( $propertyId instanceof PropertyId ) ) { |
|
| 81 | - throw new InvalidArgumentException( '$identifierProperties must contain only PropertyIds.' ); |
|
| 79 | + foreach ($identifierPropertyIds as $propertyId) { |
|
| 80 | + if (!($propertyId instanceof PropertyId)) { |
|
| 81 | + throw new InvalidArgumentException('$identifierProperties must contain only PropertyIds.'); |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - $db = wfGetDB( DB_REPLICA ); |
|
| 85 | + $db = wfGetDB(DB_REPLICA); |
|
| 86 | 86 | $identifierPropertyIds = array_map( |
| 87 | - function( PropertyId $id ) { |
|
| 87 | + function(PropertyId $id) { |
|
| 88 | 88 | return $id->getSerialization(); |
| 89 | 89 | }, |
| 90 | 90 | $identifierPropertyIds |
@@ -97,13 +97,13 @@ discard block |
||
| 97 | 97 | ] |
| 98 | 98 | ); |
| 99 | 99 | $dumpIds = []; |
| 100 | - foreach ( $result as $row ) { |
|
| 101 | - if ( !in_array( $row->dump_id, $dumpIds ) ) { |
|
| 100 | + foreach ($result as $row) { |
|
| 101 | + if (!in_array($row->dump_id, $dumpIds)) { |
|
| 102 | 102 | $dumpIds[] = $row->dump_id; |
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - return $this->getWithIds( $dumpIds ); |
|
| 106 | + return $this->getWithIds($dumpIds); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @return DumpMetaInformation[] |
| 114 | 114 | */ |
| 115 | 115 | public function getAll() { |
| 116 | - $db = wfGetDB( DB_REPLICA ); |
|
| 116 | + $db = wfGetDB(DB_REPLICA); |
|
| 117 | 117 | $result = $db->select( |
| 118 | 118 | [ |
| 119 | 119 | self::META_TABLE_NAME, |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | ] |
| 132 | 132 | ); |
| 133 | 133 | |
| 134 | - return $this->buildDumpMetaInformationFromResult( $result ); |
|
| 134 | + return $this->buildDumpMetaInformationFromResult($result); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -139,34 +139,34 @@ discard block |
||
| 139 | 139 | * @return null|array |
| 140 | 140 | * @throws UnexpectedValueException |
| 141 | 141 | */ |
| 142 | - private function buildDumpMetaInformationFromResult( ResultWrapper $result ) { |
|
| 142 | + private function buildDumpMetaInformationFromResult(ResultWrapper $result) { |
|
| 143 | 143 | $aggregatedRows = []; |
| 144 | - foreach ( $result as $row ) { |
|
| 145 | - if ( array_key_exists( $row->id, $aggregatedRows ) ) { |
|
| 146 | - $propertyId = new PropertyId( $row->identifier_pid ); |
|
| 144 | + foreach ($result as $row) { |
|
| 145 | + if (array_key_exists($row->id, $aggregatedRows)) { |
|
| 146 | + $propertyId = new PropertyId($row->identifier_pid); |
|
| 147 | 147 | $aggregatedRows[$row->id]->identifier_pid[] = $propertyId; |
| 148 | 148 | } else { |
| 149 | - if ( $row->identifier_pid !== null ) { |
|
| 150 | - $propertyId = new PropertyId( $row->identifier_pid ); |
|
| 151 | - $row->identifier_pid = [ $propertyId ]; |
|
| 149 | + if ($row->identifier_pid !== null) { |
|
| 150 | + $propertyId = new PropertyId($row->identifier_pid); |
|
| 151 | + $row->identifier_pid = [$propertyId]; |
|
| 152 | 152 | } |
| 153 | 153 | $aggregatedRows[$row->id] = $row; |
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | $dumpMetaInformation = []; |
| 158 | - foreach ( $aggregatedRows as $row ) { |
|
| 158 | + foreach ($aggregatedRows as $row) { |
|
| 159 | 159 | $dumpId = $row->id; |
| 160 | - $sourceItemId = new ItemId( $row->source_qid ); |
|
| 161 | - $importDate = wfTimestamp( TS_MW, $row->import_date ); |
|
| 160 | + $sourceItemId = new ItemId($row->source_qid); |
|
| 161 | + $importDate = wfTimestamp(TS_MW, $row->import_date); |
|
| 162 | 162 | $language = $row->language; |
| 163 | 163 | $sourceUrl = $row->source_url; |
| 164 | 164 | $size = (int)$row->size; |
| 165 | - $licenseItemId = new ItemId( $row->license_qid ); |
|
| 165 | + $licenseItemId = new ItemId($row->license_qid); |
|
| 166 | 166 | $identifierPropertyIds = $row->identifier_pid; |
| 167 | 167 | |
| 168 | 168 | $dumpMetaInformation[$row->dump_id] = |
| 169 | - new DumpMetaInformation( $dumpId, |
|
| 169 | + new DumpMetaInformation($dumpId, |
|
| 170 | 170 | $sourceItemId, |
| 171 | 171 | $identifierPropertyIds, |
| 172 | 172 | $importDate, |
@@ -185,22 +185,22 @@ discard block |
||
| 185 | 185 | * |
| 186 | 186 | * @param DumpMetaInformation $dumpMetaInformation |
| 187 | 187 | */ |
| 188 | - public function save( DumpMetaInformation $dumpMetaInformation ) { |
|
| 189 | - $db = wfGetDB( DB_REPLICA ); |
|
| 188 | + public function save(DumpMetaInformation $dumpMetaInformation) { |
|
| 189 | + $db = wfGetDB(DB_REPLICA); |
|
| 190 | 190 | $dumpId = $dumpMetaInformation->getDumpId(); |
| 191 | - $accumulator = $this->getDumpInformationFields( $db, $dumpMetaInformation ); |
|
| 191 | + $accumulator = $this->getDumpInformationFields($db, $dumpMetaInformation); |
|
| 192 | 192 | |
| 193 | 193 | $existing = $db->selectRow( |
| 194 | 194 | self::META_TABLE_NAME, |
| 195 | - [ 'id' ], |
|
| 196 | - [ 'id' => $dumpId ] |
|
| 195 | + ['id'], |
|
| 196 | + ['id' => $dumpId] |
|
| 197 | 197 | ); |
| 198 | 198 | |
| 199 | - if ( $existing ) { |
|
| 199 | + if ($existing) { |
|
| 200 | 200 | $db->update( |
| 201 | 201 | self::META_TABLE_NAME, |
| 202 | 202 | $accumulator, |
| 203 | - [ 'id' => $dumpId ] |
|
| 203 | + ['id' => $dumpId] |
|
| 204 | 204 | ); |
| 205 | 205 | } else { |
| 206 | 206 | $db->insert( |
@@ -211,12 +211,12 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | $db->delete( |
| 213 | 213 | self::IDENTIFIER_PROPERTIES_TABLE_NAME, |
| 214 | - [ 'dump_id' => $dumpId ] |
|
| 214 | + ['dump_id' => $dumpId] |
|
| 215 | 215 | ); |
| 216 | 216 | $db->insert( |
| 217 | 217 | self::IDENTIFIER_PROPERTIES_TABLE_NAME, |
| 218 | 218 | array_map( |
| 219 | - function ( PropertyId $identifierPropertyId ) use ( $dumpId ) { |
|
| 219 | + function(PropertyId $identifierPropertyId) use ($dumpId) { |
|
| 220 | 220 | return [ |
| 221 | 221 | 'dump_id' => $dumpId, |
| 222 | 222 | 'identifier_pid' => $identifierPropertyId->getSerialization() |
@@ -232,11 +232,11 @@ discard block |
||
| 232 | 232 | * @param DumpMetaInformation $dumpMetaInformation |
| 233 | 233 | * @return array |
| 234 | 234 | */ |
| 235 | - private function getDumpInformationFields( IDatabase $db, DumpMetaInformation $dumpMetaInformation ) { |
|
| 235 | + private function getDumpInformationFields(IDatabase $db, DumpMetaInformation $dumpMetaInformation) { |
|
| 236 | 236 | return [ |
| 237 | 237 | 'id' => $dumpMetaInformation->getDumpId(), |
| 238 | 238 | 'source_qid' => $dumpMetaInformation->getSourceItemId()->getSerialization(), |
| 239 | - 'import_date' => $db->timestamp( $dumpMetaInformation->getImportDate() ), |
|
| 239 | + 'import_date' => $db->timestamp($dumpMetaInformation->getImportDate()), |
|
| 240 | 240 | 'language' => $dumpMetaInformation->getLanguageCode(), |
| 241 | 241 | 'source_url' => $dumpMetaInformation->getSourceUrl(), |
| 242 | 242 | 'size' => $dumpMetaInformation->getSize(), |