@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @param StringComparer $stringComparer |
24 | 24 | */ |
25 | - public function __construct( StringComparer $stringComparer ) { |
|
25 | + public function __construct(StringComparer $stringComparer) { |
|
26 | 26 | $this->stringComparer = $stringComparer; |
27 | 27 | } |
28 | 28 | |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | * @throws InvalidArgumentException |
36 | 36 | * @return string|null One of the ComparisonResult::STATUS_... constants. |
37 | 37 | */ |
38 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
39 | - if ( !$this->canCompare( $value, $comparativeValue ) ) { |
|
40 | - throw new InvalidArgumentException( 'Given values can not be compared using this comparer.' ); |
|
38 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
39 | + if (!$this->canCompare($value, $comparativeValue)) { |
|
40 | + throw new InvalidArgumentException('Given values can not be compared using this comparer.'); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @var MonolingualTextValue $comparativeValue |
46 | 46 | */ |
47 | 47 | |
48 | - if ( $value->getLanguageCode() === $comparativeValue->getLanguageCode() ) { |
|
49 | - return $this->stringComparer->compare( $value->getText(), $comparativeValue->getText() ); |
|
48 | + if ($value->getLanguageCode() === $comparativeValue->getLanguageCode()) { |
|
49 | + return $this->stringComparer->compare($value->getText(), $comparativeValue->getText()); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | return null; |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param DataValue $comparativeValue |
60 | 60 | * @return bool |
61 | 61 | */ |
62 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
62 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
63 | 63 | return $value instanceof MonolingualTextValue && $comparativeValue instanceof MonolingualTextValue; |
64 | 64 | } |
65 | 65 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @param StringComparer $stringComparer |
24 | 24 | */ |
25 | - public function __construct( StringComparer $stringComparer ) { |
|
25 | + public function __construct(StringComparer $stringComparer) { |
|
26 | 26 | $this->stringComparer = $stringComparer; |
27 | 27 | } |
28 | 28 | |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | * @throws InvalidArgumentException |
36 | 36 | * @return string|null One of the ComparisonResult::STATUS_... constants. |
37 | 37 | */ |
38 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
39 | - if ( !$this->canCompare( $value, $comparativeValue ) ) { |
|
40 | - throw new InvalidArgumentException( 'Given values can not be compared using this comparer.' ); |
|
38 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
39 | + if (!$this->canCompare($value, $comparativeValue)) { |
|
40 | + throw new InvalidArgumentException('Given values can not be compared using this comparer.'); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -47,21 +47,21 @@ discard block |
||
47 | 47 | |
48 | 48 | $texts = $value->getTexts(); |
49 | 49 | $comparativeTexts = $comparativeValue->getTexts(); |
50 | - $commonLanguages = array_intersect( array_keys( $texts ), array_keys( $comparativeTexts ) ); |
|
50 | + $commonLanguages = array_intersect(array_keys($texts), array_keys($comparativeTexts)); |
|
51 | 51 | |
52 | - if ( $commonLanguages ) { |
|
52 | + if ($commonLanguages) { |
|
53 | 53 | $totalResult = ComparisonResult::STATUS_MISMATCH; |
54 | 54 | |
55 | - foreach ( $commonLanguages as $language ) { |
|
55 | + foreach ($commonLanguages as $language) { |
|
56 | 56 | $monolingualText = $texts[$language]; |
57 | 57 | $comparativeMonolingualText = $comparativeTexts[$language]; |
58 | 58 | |
59 | - $result = $this->stringComparer->compare( $monolingualText->getText(), $comparativeMonolingualText->getText() ); |
|
60 | - if ( $result !== ComparisonResult::STATUS_MISMATCH ) { |
|
59 | + $result = $this->stringComparer->compare($monolingualText->getText(), $comparativeMonolingualText->getText()); |
|
60 | + if ($result !== ComparisonResult::STATUS_MISMATCH) { |
|
61 | 61 | $totalResult = $result; |
62 | 62 | |
63 | 63 | // FIXME: This reports a partial match in a single language as a full match! |
64 | - if ( $result === ComparisonResult::STATUS_MATCH ) { |
|
64 | + if ($result === ComparisonResult::STATUS_MATCH) { |
|
65 | 65 | break; |
66 | 66 | } |
67 | 67 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @param DataValue $comparativeValue |
81 | 81 | * @return bool |
82 | 82 | */ |
83 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
83 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
84 | 84 | return $value instanceof MultilingualTextValue && $comparativeValue instanceof MultilingualTextValue; |
85 | 85 | } |
86 | 86 |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | * @throws InvalidArgumentException |
24 | 24 | * @return string One of the ComparisonResult::STATUS_... constants. |
25 | 25 | */ |
26 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
27 | - if ( !$this->canCompare( $value, $comparativeValue ) ) { |
|
28 | - throw new InvalidArgumentException( 'Given values can not be compared using this comparer.' ); |
|
26 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
27 | + if (!$this->canCompare($value, $comparativeValue)) { |
|
28 | + throw new InvalidArgumentException('Given values can not be compared using this comparer.'); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | * @var QuantityValue $comparativeValue |
34 | 34 | */ |
35 | 35 | |
36 | - if ( $comparativeValue->getLowerBound()->compare( $value->getUpperBound() ) <= 0 && |
|
37 | - $comparativeValue->getUpperBound()->compare( $value->getLowerBound() ) >= 0 |
|
36 | + if ($comparativeValue->getLowerBound()->compare($value->getUpperBound()) <= 0 && |
|
37 | + $comparativeValue->getUpperBound()->compare($value->getLowerBound()) >= 0 |
|
38 | 38 | ) { |
39 | 39 | return ComparisonResult::STATUS_MATCH; |
40 | 40 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param DataValue $comparativeValue |
50 | 50 | * @return bool |
51 | 51 | */ |
52 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
52 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
53 | 53 | return $value instanceof QuantityValue && $comparativeValue instanceof QuantityValue; |
54 | 54 | } |
55 | 55 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @param StringNormalizer $stringNormalizer |
28 | 28 | */ |
29 | - public function __construct( StringNormalizer $stringNormalizer ) { |
|
29 | + public function __construct(StringNormalizer $stringNormalizer) { |
|
30 | 30 | $this->stringNormalizer = $stringNormalizer; |
31 | 31 | } |
32 | 32 | |
@@ -37,16 +37,16 @@ discard block |
||
37 | 37 | * @param string $comparativeValue |
38 | 38 | * @return string |
39 | 39 | */ |
40 | - public function compare( $value, $comparativeValue ) { |
|
41 | - Assert::parameterType( 'string', $value, '$value' ); |
|
42 | - Assert::parameterType( 'string', $comparativeValue, '$comparativeValue' ); |
|
40 | + public function compare($value, $comparativeValue) { |
|
41 | + Assert::parameterType('string', $value, '$value'); |
|
42 | + Assert::parameterType('string', $comparativeValue, '$comparativeValue'); |
|
43 | 43 | |
44 | - $value = $this->cleanDataString( $value ); |
|
45 | - $comparativeValue = $this->cleanDataString( $comparativeValue ); |
|
44 | + $value = $this->cleanDataString($value); |
|
45 | + $comparativeValue = $this->cleanDataString($comparativeValue); |
|
46 | 46 | |
47 | - if ( $value === $comparativeValue ) { |
|
47 | + if ($value === $comparativeValue) { |
|
48 | 48 | return ComparisonResult::STATUS_MATCH; |
49 | - } elseif ( $this->checkSimilarity( $value, $comparativeValue ) ) { |
|
49 | + } elseif ($this->checkSimilarity($value, $comparativeValue)) { |
|
50 | 50 | return ComparisonResult::STATUS_PARTIAL_MATCH; |
51 | 51 | } else { |
52 | 52 | return ComparisonResult::STATUS_MISMATCH; |
@@ -60,19 +60,19 @@ discard block |
||
60 | 60 | * @param array $comparativeValues |
61 | 61 | * @return string |
62 | 62 | */ |
63 | - public function compareWithArray( $value, array $comparativeValues ) { |
|
64 | - Assert::parameterType( 'string', $value, '$value' ); |
|
65 | - Assert::parameterElementType( 'string', $comparativeValues, '$comparativeValues' ); |
|
63 | + public function compareWithArray($value, array $comparativeValues) { |
|
64 | + Assert::parameterType('string', $value, '$value'); |
|
65 | + Assert::parameterElementType('string', $comparativeValues, '$comparativeValues'); |
|
66 | 66 | |
67 | - $value = $this->cleanDataString( $value ); |
|
68 | - $comparativeValues = $this->cleanDataArray( $comparativeValues ); |
|
67 | + $value = $this->cleanDataString($value); |
|
68 | + $comparativeValues = $this->cleanDataArray($comparativeValues); |
|
69 | 69 | |
70 | - if ( in_array( $value, $comparativeValues ) ) { |
|
70 | + if (in_array($value, $comparativeValues)) { |
|
71 | 71 | return ComparisonResult::STATUS_MATCH; |
72 | 72 | } |
73 | 73 | |
74 | - foreach ( $comparativeValues as $comparativeValue ) { |
|
75 | - if ( $this->checkSimilarity( $comparativeValue, $value ) ) { |
|
74 | + foreach ($comparativeValues as $comparativeValue) { |
|
75 | + if ($this->checkSimilarity($comparativeValue, $value)) { |
|
76 | 76 | return ComparisonResult::STATUS_PARTIAL_MATCH; |
77 | 77 | } |
78 | 78 | } |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | * @param string $comparativeValue |
88 | 88 | * @return bool |
89 | 89 | */ |
90 | - private function checkSimilarity( $value, $comparativeValue ) { |
|
90 | + private function checkSimilarity($value, $comparativeValue) { |
|
91 | 91 | return |
92 | - $this->percentagePrefixSimilarity( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD || |
|
93 | - $this->percentageSuffixSimilarity( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD || |
|
94 | - $this->percentageLevenshteinDistance( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD; |
|
92 | + $this->percentagePrefixSimilarity($value, $comparativeValue) > self::SIMILARITY_THRESHOLD || |
|
93 | + $this->percentageSuffixSimilarity($value, $comparativeValue) > self::SIMILARITY_THRESHOLD || |
|
94 | + $this->percentageLevenshteinDistance($value, $comparativeValue) > self::SIMILARITY_THRESHOLD; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @return string |
103 | 103 | */ |
104 | - private function cleanDataString( $value ) { |
|
105 | - $value = $this->stringNormalizer->trimToNFC( $value ); |
|
104 | + private function cleanDataString($value) { |
|
105 | + $value = $this->stringNormalizer->trimToNFC($value); |
|
106 | 106 | |
107 | - return mb_strtolower( $value ); |
|
107 | + return mb_strtolower($value); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return array |
116 | 116 | */ |
117 | - private function cleanDataArray( array $array ) { |
|
117 | + private function cleanDataArray(array $array) { |
|
118 | 118 | |
119 | 119 | return array_map( |
120 | - array( $this, 'cleanDataString' ), |
|
120 | + array($this, 'cleanDataString'), |
|
121 | 121 | $array ); |
122 | 122 | } |
123 | 123 | |
@@ -129,19 +129,19 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return float |
131 | 131 | */ |
132 | - private function percentagePrefixSimilarity( $value, $comparativeValue ) { |
|
132 | + private function percentagePrefixSimilarity($value, $comparativeValue) { |
|
133 | 133 | $prefixLength = 0; // common prefix length |
134 | - $localLength = strlen( $value ); |
|
135 | - $externalLength = strlen( $comparativeValue ); |
|
136 | - while ( $prefixLength < min( $localLength, $externalLength ) ) { |
|
134 | + $localLength = strlen($value); |
|
135 | + $externalLength = strlen($comparativeValue); |
|
136 | + while ($prefixLength < min($localLength, $externalLength)) { |
|
137 | 137 | $c = $value[$prefixLength]; |
138 | - if ( $externalLength > $prefixLength && $comparativeValue[$prefixLength] !== $c ) { |
|
138 | + if ($externalLength > $prefixLength && $comparativeValue[$prefixLength] !== $c) { |
|
139 | 139 | break; |
140 | 140 | } |
141 | 141 | $prefixLength++; |
142 | 142 | } |
143 | 143 | |
144 | - return $prefixLength / max( $localLength, $externalLength ); |
|
144 | + return $prefixLength / max($localLength, $externalLength); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -152,19 +152,19 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return float |
154 | 154 | */ |
155 | - private function percentageSuffixSimilarity( $value, $comparativeValue ) { |
|
155 | + private function percentageSuffixSimilarity($value, $comparativeValue) { |
|
156 | 156 | $suffixLength = 0; // common suffix length |
157 | - $localLength = strlen( $value ); |
|
158 | - $externalLength = strlen( $comparativeValue ); |
|
159 | - while ( $suffixLength < min( $localLength, $externalLength ) ) { |
|
157 | + $localLength = strlen($value); |
|
158 | + $externalLength = strlen($comparativeValue); |
|
159 | + while ($suffixLength < min($localLength, $externalLength)) { |
|
160 | 160 | $c = $value[$localLength - 1 - $suffixLength]; |
161 | - if ( $externalLength > $suffixLength && $comparativeValue[$externalLength - 1 - $suffixLength] !== $c ) { |
|
161 | + if ($externalLength > $suffixLength && $comparativeValue[$externalLength - 1 - $suffixLength] !== $c) { |
|
162 | 162 | break; |
163 | 163 | } |
164 | 164 | $suffixLength++; |
165 | 165 | } |
166 | 166 | |
167 | - return $suffixLength / max( $localLength, $externalLength ); |
|
167 | + return $suffixLength / max($localLength, $externalLength); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return float |
177 | 177 | */ |
178 | - private function percentageLevenshteinDistance( $value, $comparativeValue ) { |
|
179 | - $distance = levenshtein( $value, $comparativeValue ); |
|
180 | - $percentage = 1.0 - $distance / max( strlen( $value ), strlen( $comparativeValue ) ); |
|
178 | + private function percentageLevenshteinDistance($value, $comparativeValue) { |
|
179 | + $distance = levenshtein($value, $comparativeValue); |
|
180 | + $percentage = 1.0 - $distance / max(strlen($value), strlen($comparativeValue)); |
|
181 | 181 | |
182 | 182 | return $percentage; |
183 | 183 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * @param StringComparer $stringComparer |
23 | 23 | */ |
24 | - public function __construct( StringComparer $stringComparer ) { |
|
24 | + public function __construct(StringComparer $stringComparer) { |
|
25 | 25 | $this->stringComparer = $stringComparer; |
26 | 26 | } |
27 | 27 | |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | * @throws InvalidArgumentException |
35 | 35 | * @return string One of the ComparisonResult::STATUS_... constants. |
36 | 36 | */ |
37 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
38 | - if ( !$this->canCompare( $value, $comparativeValue ) ) { |
|
39 | - throw new InvalidArgumentException( 'Given values can not be compared using this comparer.' ); |
|
37 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
38 | + if (!$this->canCompare($value, $comparativeValue)) { |
|
39 | + throw new InvalidArgumentException('Given values can not be compared using this comparer.'); |
|
40 | 40 | } |
41 | 41 | |
42 | - return $this->stringComparer->compare( $value->getValue(), $comparativeValue->getValue() ); |
|
42 | + return $this->stringComparer->compare($value->getValue(), $comparativeValue->getValue()); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param DataValue $comparativeValue |
50 | 50 | * @return bool |
51 | 51 | */ |
52 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
52 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
53 | 53 | return $value instanceof StringValue && $comparativeValue instanceof StringValue; |
54 | 54 | } |
55 | 55 |
@@ -30,9 +30,9 @@ 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 | 38 | /** |
@@ -42,38 +42,38 @@ discard block |
||
42 | 42 | |
43 | 43 | $result = ComparisonResult::STATUS_MISMATCH; |
44 | 44 | |
45 | - if ( !preg_match( '/^([-+]?)(\d*)((\d{4}\b).*)/', $value->getTime(), $localMatches ) |
|
46 | - || !preg_match( '/^([-+]?)(\d*)((\d{4}\b).*)/', $comparativeValue->getTime(), $externalMatches ) |
|
45 | + if (!preg_match('/^([-+]?)(\d*)((\d{4}\b).*)/', $value->getTime(), $localMatches) |
|
46 | + || !preg_match('/^([-+]?)(\d*)((\d{4}\b).*)/', $comparativeValue->getTime(), $externalMatches) |
|
47 | 47 | ) { |
48 | 48 | return ComparisonResult::STATUS_MISMATCH; |
49 | 49 | } |
50 | - list( , $localSign, $localYearHigh, $localMwTime, $localYearLow ) = $localMatches; |
|
51 | - list( , $externalSign, $externalYearHigh, $externalMwTime, $externalYearLow ) = $externalMatches; |
|
52 | - if ( $localSign !== $externalSign && ( $localYearHigh . $localYearLow !== '0000' |
|
53 | - || $externalYearHigh . $externalYearLow !== '0000' ) |
|
50 | + list(, $localSign, $localYearHigh, $localMwTime, $localYearLow) = $localMatches; |
|
51 | + list(, $externalSign, $externalYearHigh, $externalMwTime, $externalYearLow) = $externalMatches; |
|
52 | + if ($localSign !== $externalSign && ($localYearHigh . $localYearLow !== '0000' |
|
53 | + || $externalYearHigh . $externalYearLow !== '0000') |
|
54 | 54 | ) { |
55 | 55 | return ComparisonResult::STATUS_MISMATCH; |
56 | 56 | } |
57 | 57 | |
58 | 58 | try { |
59 | - $localTimestamp = new MWTimestamp( $localMwTime ); |
|
60 | - $externalTimestamp = new MWTimestamp( $externalMwTime ); |
|
61 | - $diff = $localTimestamp->diff( $externalTimestamp ); |
|
62 | - $diff->y += abs( $localYearHigh - $externalYearHigh ) * 10000; |
|
59 | + $localTimestamp = new MWTimestamp($localMwTime); |
|
60 | + $externalTimestamp = new MWTimestamp($externalMwTime); |
|
61 | + $diff = $localTimestamp->diff($externalTimestamp); |
|
62 | + $diff->y += abs($localYearHigh - $externalYearHigh) * 10000; |
|
63 | 63 | |
64 | - if ( $value->getPrecision() === $comparativeValue->getPrecision() |
|
65 | - && $this->resultOfDiffWithPrecision( $diff, $value->getPrecision() ) |
|
64 | + if ($value->getPrecision() === $comparativeValue->getPrecision() |
|
65 | + && $this->resultOfDiffWithPrecision($diff, $value->getPrecision()) |
|
66 | 66 | ) { |
67 | 67 | $result = ComparisonResult::STATUS_MATCH; |
68 | 68 | } elseif ( |
69 | 69 | $this->resultOfDiffWithPrecision( |
70 | 70 | $diff, |
71 | - min( $value->getPrecision(), $comparativeValue->getPrecision() ) |
|
71 | + min($value->getPrecision(), $comparativeValue->getPrecision()) |
|
72 | 72 | ) |
73 | 73 | ) { |
74 | 74 | $result = ComparisonResult::STATUS_PARTIAL_MATCH; |
75 | 75 | } |
76 | - } catch ( TimestampException $ex ) { |
|
76 | + } catch (TimestampException $ex) { |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | return $result; |
@@ -87,10 +87,10 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @return bool |
89 | 89 | */ |
90 | - private function resultOfDiffWithPrecision( DateInterval $diff, $precision ) { |
|
90 | + private function resultOfDiffWithPrecision(DateInterval $diff, $precision) { |
|
91 | 91 | $result = true; |
92 | 92 | |
93 | - switch ( $precision ) { |
|
93 | + switch ($precision) { |
|
94 | 94 | case TimeValue::PRECISION_SECOND: |
95 | 95 | $result = $diff->s === 0; |
96 | 96 | // Fall through with no break/return. This is critical for this algorithm. |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @return ValueParser |
136 | 136 | */ |
137 | - protected function getExternalValueParser( DumpMetaInformation $dumpMetaInformation ) { |
|
137 | + protected function getExternalValueParser(DumpMetaInformation $dumpMetaInformation) { |
|
138 | 138 | $parserOptions = new ParserOptions(); |
139 | - $parserOptions->setOption( ValueParser::OPT_LANG, $dumpMetaInformation->getLanguageCode() ); |
|
140 | - $timeParserFactory = new TimeParserFactory( $parserOptions ); |
|
139 | + $parserOptions->setOption(ValueParser::OPT_LANG, $dumpMetaInformation->getLanguageCode()); |
|
140 | + $timeParserFactory = new TimeParserFactory($parserOptions); |
|
141 | 141 | |
142 | 142 | return $timeParserFactory->getTimeParser(); |
143 | 143 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @return bool |
152 | 152 | */ |
153 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
153 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
154 | 154 | return $value instanceof TimeValue && $comparativeValue instanceof TimeValue; |
155 | 155 | } |
156 | 156 |
@@ -94,22 +94,22 @@ discard block |
||
94 | 94 | * @return CrossCheckResultList |
95 | 95 | * @throws InvalidArgumentException |
96 | 96 | */ |
97 | - public function crossCheckStatements( StatementList $entityStatements, StatementList $statements ) { |
|
97 | + public function crossCheckStatements(StatementList $entityStatements, StatementList $statements) { |
|
98 | 98 | $statementsOfEntity = $entityStatements->toArray(); |
99 | 99 | |
100 | - foreach ( $statements as $statement ) { |
|
101 | - if ( !in_array( $statement, $statementsOfEntity ) ) { |
|
102 | - throw new InvalidArgumentException( 'All statements in $statements must belong to the entity.' ); |
|
100 | + foreach ($statements as $statement) { |
|
101 | + if (!in_array($statement, $statementsOfEntity)) { |
|
102 | + throw new InvalidArgumentException('All statements in $statements must belong to the entity.'); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | 106 | $resultList = new CrossCheckResultList(); |
107 | - if ( $statements->count() > 0 ) { |
|
108 | - $applicableDumps = $this->getApplicableDumps( $entityStatements ); |
|
109 | - foreach ( $applicableDumps as $identifierPropertyId => $dumpMetaInformationList ) { |
|
110 | - $identifierPropertyId = new PropertyId( $identifierPropertyId ); |
|
107 | + if ($statements->count() > 0) { |
|
108 | + $applicableDumps = $this->getApplicableDumps($entityStatements); |
|
109 | + foreach ($applicableDumps as $identifierPropertyId => $dumpMetaInformationList) { |
|
110 | + $identifierPropertyId = new PropertyId($identifierPropertyId); |
|
111 | 111 | |
112 | - if( $this->isIdentifierProperty( $identifierPropertyId ) ) { |
|
112 | + if ($this->isIdentifierProperty($identifierPropertyId)) { |
|
113 | 113 | $resultList->merge( |
114 | 114 | $this->crossCheckStatementsWithIdentifier( |
115 | 115 | $entityStatements, |
@@ -132,17 +132,17 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return array[] |
134 | 134 | */ |
135 | - private function getApplicableDumps( StatementList $statements ) { |
|
135 | + private function getApplicableDumps(StatementList $statements) { |
|
136 | 136 | $applicableDumps = array(); |
137 | 137 | $identifierPropertyIds = $statements->getPropertyIds(); |
138 | 138 | $dumpMetaInformation = $this->dumpMetaInformationLookup->getWithIdentifierProperties( |
139 | 139 | $identifierPropertyIds |
140 | 140 | ); |
141 | 141 | |
142 | - foreach ( $dumpMetaInformation as $dump ) { |
|
143 | - foreach ( $dump->getIdentifierPropertyIds() as $identifierPropertyId ) { |
|
142 | + foreach ($dumpMetaInformation as $dump) { |
|
143 | + foreach ($dump->getIdentifierPropertyIds() as $identifierPropertyId) { |
|
144 | 144 | $serialization = $identifierPropertyId->getSerialization(); |
145 | - $applicableDumps[ $serialization ][ $dump->getDumpId() ] = $dump; |
|
145 | + $applicableDumps[$serialization][$dump->getDumpId()] = $dump; |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
@@ -167,36 +167,36 @@ discard block |
||
167 | 167 | ) { |
168 | 168 | $resultList = new CrossCheckResultList(); |
169 | 169 | |
170 | - $externalIds = $this->getExternalIds( $entityStatements, $identifierPropertyId ); |
|
171 | - if( !$externalIds ) { |
|
170 | + $externalIds = $this->getExternalIds($entityStatements, $identifierPropertyId); |
|
171 | + if (!$externalIds) { |
|
172 | 172 | return $resultList; |
173 | 173 | } |
174 | 174 | |
175 | 175 | $dumpIds = array_map( |
176 | - function ( DumpMetaInformation $dumpMetaInformation ) { |
|
176 | + function(DumpMetaInformation $dumpMetaInformation) { |
|
177 | 177 | return $dumpMetaInformation->getDumpId(); |
178 | 178 | }, |
179 | 179 | $dumpMetaInformationList |
180 | 180 | ); |
181 | - $externalData = $this->externalDataRepo->getExternalData( $dumpIds, $externalIds, $statements->getPropertyIds() ); |
|
181 | + $externalData = $this->externalDataRepo->getExternalData($dumpIds, $externalIds, $statements->getPropertyIds()); |
|
182 | 182 | |
183 | - foreach ( $externalData as $dumpId => $externalDataPerDump ) { |
|
184 | - $dumpMetaInformation = $dumpMetaInformationList[ $dumpId ]; |
|
183 | + foreach ($externalData as $dumpId => $externalDataPerDump) { |
|
184 | + $dumpMetaInformation = $dumpMetaInformationList[$dumpId]; |
|
185 | 185 | $comparativeValueParser = $this->valueParserFactory->newComparativeValueParser( |
186 | 186 | $dumpMetaInformation->getLanguageCode() |
187 | 187 | ); |
188 | 188 | |
189 | - foreach ( $externalDataPerDump as $externalId => $externalDataPerId ) { |
|
189 | + foreach ($externalDataPerDump as $externalId => $externalDataPerId) { |
|
190 | 190 | $externalId = (string)$externalId; |
191 | - foreach ( $externalDataPerId as $propertyId => $externalValues ) { |
|
192 | - $propertyId = new PropertyId( $propertyId ); |
|
191 | + foreach ($externalDataPerId as $propertyId => $externalValues) { |
|
192 | + $propertyId = new PropertyId($propertyId); |
|
193 | 193 | $resultList->merge( |
194 | 194 | $this->crossCheckExternalValues( |
195 | 195 | $dumpMetaInformation, |
196 | 196 | $identifierPropertyId, |
197 | 197 | $externalId, |
198 | 198 | $externalValues, |
199 | - $statements->getByPropertyId( $propertyId ), |
|
199 | + $statements->getByPropertyId($propertyId), |
|
200 | 200 | $comparativeValueParser |
201 | 201 | ) |
202 | 202 | ); |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | ComparativeValueParser $comparativeValueParser |
227 | 227 | ) { |
228 | 228 | $resultList = new CrossCheckResultList(); |
229 | - foreach ( $statements as $statement ) { |
|
230 | - $comparisonResult = $this->compareStatement( $statement, $externalValues, $comparativeValueParser ); |
|
229 | + foreach ($statements as $statement) { |
|
230 | + $comparisonResult = $this->compareStatement($statement, $externalValues, $comparativeValueParser); |
|
231 | 231 | |
232 | - if ( $comparisonResult ) { |
|
232 | + if ($comparisonResult) { |
|
233 | 233 | $referencesResult = $this->referenceHandler->checkForReferences( |
234 | 234 | $statement, |
235 | 235 | $identifierPropertyId, |
@@ -263,32 +263,32 @@ discard block |
||
263 | 263 | * @return ComparisonResult|bool |
264 | 264 | */ |
265 | 265 | private function compareStatement( |
266 | - Statement $statement,array $externalValues, |
|
266 | + Statement $statement, array $externalValues, |
|
267 | 267 | ComparativeValueParser $comparativeValueParser |
268 | 268 | ) { |
269 | 269 | $mainSnak = $statement->getMainSnak(); |
270 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
270 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
271 | 271 | $dataValue = $mainSnak->getDataValue(); |
272 | 272 | |
273 | 273 | $results = array(); |
274 | - $comparativeValues = $this->parseExternalValues( $dataValue, $externalValues, $comparativeValueParser ); |
|
275 | - foreach ( $comparativeValues as $comparativeValue ) { |
|
276 | - $result = $this->dataValueComparer->compare( $dataValue, $comparativeValue ); |
|
277 | - if( $result ) { |
|
274 | + $comparativeValues = $this->parseExternalValues($dataValue, $externalValues, $comparativeValueParser); |
|
275 | + foreach ($comparativeValues as $comparativeValue) { |
|
276 | + $result = $this->dataValueComparer->compare($dataValue, $comparativeValue); |
|
277 | + if ($result) { |
|
278 | 278 | $results[] = $result; |
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | - if( $results ) { |
|
282 | + if ($results) { |
|
283 | 283 | $result = ComparisonResult::STATUS_MISMATCH; |
284 | - if( in_array( ComparisonResult::STATUS_MATCH, $results ) ) { |
|
284 | + if (in_array(ComparisonResult::STATUS_MATCH, $results)) { |
|
285 | 285 | $result = ComparisonResult::STATUS_MATCH; |
286 | 286 | } |
287 | - elseif( in_array( ComparisonResult::STATUS_PARTIAL_MATCH, $results ) ) { |
|
287 | + elseif (in_array(ComparisonResult::STATUS_PARTIAL_MATCH, $results)) { |
|
288 | 288 | $result = ComparisonResult::STATUS_PARTIAL_MATCH; |
289 | 289 | } |
290 | 290 | |
291 | - return new ComparisonResult( $dataValue, $comparativeValues, $result ); |
|
291 | + return new ComparisonResult($dataValue, $comparativeValues, $result); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
@@ -308,14 +308,14 @@ discard block |
||
308 | 308 | ComparativeValueParser $comparativeValueParser |
309 | 309 | ) { |
310 | 310 | $parsedValues = array(); |
311 | - foreach ( $externalValues as $externalValue ) { |
|
311 | + foreach ($externalValues as $externalValue) { |
|
312 | 312 | try { |
313 | - $parsedValue = $comparativeValueParser->parse( $externalValue, $dataValue->getType() ); |
|
314 | - if( $parsedValue ) { |
|
313 | + $parsedValue = $comparativeValueParser->parse($externalValue, $dataValue->getType()); |
|
314 | + if ($parsedValue) { |
|
315 | 315 | $parsedValues[] = $parsedValue; |
316 | 316 | } |
317 | 317 | } |
318 | - catch( ParseException $e ) {} |
|
318 | + catch (ParseException $e) {} |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | return $parsedValues; |
@@ -329,12 +329,12 @@ discard block |
||
329 | 329 | * |
330 | 330 | * @return string[] |
331 | 331 | */ |
332 | - private function getExternalIds( StatementList $statements, PropertyId $identifierPropertyId ) { |
|
332 | + private function getExternalIds(StatementList $statements, PropertyId $identifierPropertyId) { |
|
333 | 333 | $externalIds = array(); |
334 | - $identifierStatements = $statements->getByPropertyId( $identifierPropertyId ); |
|
335 | - $values = $this->getDataValues( $identifierStatements ); |
|
336 | - foreach ( $values as $value ) { |
|
337 | - if ( $value instanceof StringValue ) { |
|
334 | + $identifierStatements = $statements->getByPropertyId($identifierPropertyId); |
|
335 | + $values = $this->getDataValues($identifierStatements); |
|
336 | + foreach ($values as $value) { |
|
337 | + if ($value instanceof StringValue) { |
|
338 | 338 | $externalIds[] = $value->getValue(); |
339 | 339 | } |
340 | 340 | } |
@@ -346,14 +346,14 @@ discard block |
||
346 | 346 | * @param PropertyId $identifierPropertyId |
347 | 347 | * @return bool |
348 | 348 | */ |
349 | - private function isIdentifierProperty( PropertyId $identifierPropertyId ) { |
|
350 | - $property = $this->entityLookup->getEntity( $identifierPropertyId ); |
|
351 | - $instanceOfPropertyId = new PropertyId( INSTANCE_OF_PID ); |
|
352 | - $statements = $property->getStatements()->getByPropertyId( $instanceOfPropertyId ); |
|
353 | - $values = $this->getDataValues( $statements ); |
|
354 | - foreach ( $values as $value ) { |
|
355 | - if( $value instanceof EntityIdValue ) { |
|
356 | - if( $value->getEntityId()->getSerialization() === IDENTIFIER_PROPERTY_QID ) { |
|
349 | + private function isIdentifierProperty(PropertyId $identifierPropertyId) { |
|
350 | + $property = $this->entityLookup->getEntity($identifierPropertyId); |
|
351 | + $instanceOfPropertyId = new PropertyId(INSTANCE_OF_PID); |
|
352 | + $statements = $property->getStatements()->getByPropertyId($instanceOfPropertyId); |
|
353 | + $values = $this->getDataValues($statements); |
|
354 | + foreach ($values as $value) { |
|
355 | + if ($value instanceof EntityIdValue) { |
|
356 | + if ($value->getEntityId()->getSerialization() === IDENTIFIER_PROPERTY_QID) { |
|
357 | 357 | return true; |
358 | 358 | } |
359 | 359 | } |
@@ -368,11 +368,11 @@ discard block |
||
368 | 368 | * @param StatementList $statementList |
369 | 369 | * @return DataValue[] |
370 | 370 | */ |
371 | - private function getDataValues( StatementList $statementList ){ |
|
371 | + private function getDataValues(StatementList $statementList) { |
|
372 | 372 | $dataValues = array(); |
373 | - foreach ( $statementList as $statement ) { |
|
373 | + foreach ($statementList as $statement) { |
|
374 | 374 | $mainSnak = $statement->getMainSnak(); |
375 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
375 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
376 | 376 | $dataValues[] = $mainSnak->getDataValue(); |
377 | 377 | } |
378 | 378 | } |
@@ -283,8 +283,7 @@ discard block |
||
283 | 283 | $result = ComparisonResult::STATUS_MISMATCH; |
284 | 284 | if( in_array( ComparisonResult::STATUS_MATCH, $results ) ) { |
285 | 285 | $result = ComparisonResult::STATUS_MATCH; |
286 | - } |
|
287 | - elseif( in_array( ComparisonResult::STATUS_PARTIAL_MATCH, $results ) ) { |
|
286 | + } elseif( in_array( ComparisonResult::STATUS_PARTIAL_MATCH, $results ) ) { |
|
288 | 287 | $result = ComparisonResult::STATUS_PARTIAL_MATCH; |
289 | 288 | } |
290 | 289 | |
@@ -314,8 +313,7 @@ discard block |
||
314 | 313 | if( $parsedValue ) { |
315 | 314 | $parsedValues[] = $parsedValue; |
316 | 315 | } |
317 | - } |
|
318 | - catch( ParseException $e ) {} |
|
316 | + } catch( ParseException $e ) {} |
|
319 | 317 | } |
320 | 318 | |
321 | 319 | return $parsedValues; |
@@ -34,17 +34,17 @@ discard block |
||
34 | 34 | * @throws InvalidArgumentException |
35 | 35 | * @return ReferenceResult |
36 | 36 | */ |
37 | - public function checkForReferences( Statement $statement, PropertyId $identifierPropertyId, $externalId, DumpMetaInformation $dumpMetaInformation ) { |
|
38 | - Assert::parameterType( 'string', $externalId, '$externalId' ); |
|
37 | + public function checkForReferences(Statement $statement, PropertyId $identifierPropertyId, $externalId, DumpMetaInformation $dumpMetaInformation) { |
|
38 | + Assert::parameterType('string', $externalId, '$externalId'); |
|
39 | 39 | |
40 | - if ( count( $statement->getReferences() ) === 0 ) { |
|
40 | + if (count($statement->getReferences()) === 0) { |
|
41 | 41 | $status = ReferenceResult::STATUS_REFERENCES_MISSING; |
42 | 42 | } else { |
43 | 43 | $status = ReferenceResult::STATUS_REFERENCES_STATED; |
44 | 44 | } |
45 | 45 | |
46 | - $externalReference = $this->buildReference( $identifierPropertyId, $externalId, $dumpMetaInformation ); |
|
47 | - return new ReferenceResult( $status, $externalReference ); |
|
46 | + $externalReference = $this->buildReference($identifierPropertyId, $externalId, $dumpMetaInformation); |
|
47 | + return new ReferenceResult($status, $externalReference); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | * @param DumpMetaInformation $dumpMetaInformation |
56 | 56 | * @return Reference |
57 | 57 | */ |
58 | - private function buildReference( PropertyId $identifierPropertyId, $externalId, DumpMetaInformation $dumpMetaInformation ) { |
|
58 | + private function buildReference(PropertyId $identifierPropertyId, $externalId, DumpMetaInformation $dumpMetaInformation) { |
|
59 | 59 | $sourceItemId = $dumpMetaInformation->getSourceItemId(); |
60 | 60 | $statedInAuthoritySnak = new PropertyValueSnak( |
61 | - new PropertyId( STATED_IN_PID ), |
|
62 | - new EntityIdValue( $sourceItemId ) |
|
61 | + new PropertyId(STATED_IN_PID), |
|
62 | + new EntityIdValue($sourceItemId) |
|
63 | 63 | ); |
64 | 64 | $authorityWithExternalIdSnak = new PropertyValueSnak( |
65 | 65 | $identifierPropertyId, |
66 | - new StringValue( $externalId ) |
|
66 | + new StringValue($externalId) |
|
67 | 67 | ); |
68 | 68 | |
69 | 69 | return new Reference( |
@@ -45,12 +45,12 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @throws InvalidArgumentException |
47 | 47 | */ |
48 | - public function __construct( DataValue $localValue, array $externalValues, $status ) { |
|
49 | - Assert::parameterElementType( 'DataValues\DataValue', $externalValues, '$externalValues' ); |
|
48 | + public function __construct(DataValue $localValue, array $externalValues, $status) { |
|
49 | + Assert::parameterElementType('DataValues\DataValue', $externalValues, '$externalValues'); |
|
50 | 50 | |
51 | 51 | $this->localValue = $localValue; |
52 | 52 | $this->externalValues = $externalValues; |
53 | - $this->setStatus( $status ); |
|
53 | + $this->setStatus($status); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @throws InvalidArgumentException |
81 | 81 | */ |
82 | - private function setStatus( $status ) { |
|
83 | - Assert::parameterType( 'string', $status, '$status' ); |
|
84 | - if ( !in_array( |
|
82 | + private function setStatus($status) { |
|
83 | + Assert::parameterType('string', $status, '$status'); |
|
84 | + if (!in_array( |
|
85 | 85 | $status, |
86 | - array( self::STATUS_MATCH, self::STATUS_PARTIAL_MATCH, self::STATUS_MISMATCH ) |
|
86 | + array(self::STATUS_MATCH, self::STATUS_PARTIAL_MATCH, self::STATUS_MISMATCH) |
|
87 | 87 | ) |
88 | 88 | ) { |
89 | - throw new InvalidArgumentException( '$status must be one of the status constants.' ); |
|
89 | + throw new InvalidArgumentException('$status must be one of the status constants.'); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | $this->status = $status; |