Completed
Push — master ( 4a37ad...70ff8f )
by
unknown
01:57
created
includes/CrossCheck/Comparer/MultilingualTextValueComparer.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
includes/CrossCheck/Comparer/StringComparer.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
includes/CrossCheck/Comparer/DataValueComparerFactory.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 	/**
Please login to merge, or discard this patch.
includes/CrossCheck/ValueParser/StringValueParser.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
includes/CrossCheck/ValueParser/MultilingualTextValueParser.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
includes/Serializer/SerializerFactory.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 */
21 21
 	private $referenceSerializer;
22 22
 
23
-	public function __construct( Serializer $dataValueSerializer, Serializer $referenceSerializer ) {
23
+	public function __construct(Serializer $dataValueSerializer, Serializer $referenceSerializer) {
24 24
 		$this->dataValueSerializer = $dataValueSerializer;
25 25
 		$this->referenceSerializer = $referenceSerializer;
26 26
 	}
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @return Serializer
43 43
 	 */
44 44
 	public function newComparisonResultSerializer() {
45
-		return new ComparisonResultSerializer( $this->dataValueSerializer );
45
+		return new ComparisonResultSerializer($this->dataValueSerializer);
46 46
 	}
47 47
 
48 48
 	/**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @return Serializer
74 74
 	 */
75 75
 	public function newReferenceResultSerializer() {
76
-		return new ReferenceResultSerializer( $this->referenceSerializer );
76
+		return new ReferenceResultSerializer($this->referenceSerializer);
77 77
 	}
78 78
 
79 79
 }
Please login to merge, or discard this patch.
includes/Serializer/ComparisonResultSerializer.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	 */
19 19
 	private $dataValueSerializer;
20 20
 
21
-	public function __construct( Serializer $dataValueSerializer ) {
21
+	public function __construct(Serializer $dataValueSerializer) {
22 22
 		$this->dataValueSerializer = $dataValueSerializer;
23 23
 	}
24 24
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @return bool
31 31
 	 */
32
-	public function isSerializerFor( $object ) {
32
+	public function isSerializerFor($object) {
33 33
 		return $object instanceof ComparisonResult;
34 34
 	}
35 35
 
@@ -41,29 +41,29 @@  discard block
 block discarded – undo
41 41
 	 * @return array
42 42
 	 * @throws UnsupportedObjectException
43 43
 	 */
44
-	public function serialize( $object ) {
45
-		if ( !$this->isSerializerFor( $object ) ) {
44
+	public function serialize($object) {
45
+		if (!$this->isSerializerFor($object)) {
46 46
 			throw new UnsupportedObjectException(
47 47
 				$object,
48 48
 				'ComparisonResultSerializer can only serialize ComparisonResult objects.'
49 49
 			);
50 50
 		}
51 51
 
52
-		return $this->getSerialized( $object );
52
+		return $this->getSerialized($object);
53 53
 	}
54 54
 
55
-	private function getSerialized( ComparisonResult $comparisonResult ) {
55
+	private function getSerialized(ComparisonResult $comparisonResult) {
56 56
 		$dataValueSerializer = $this->dataValueSerializer;
57 57
 		$externalValues = array_map(
58
-			function ( $dataValue ) use ( $dataValueSerializer ) {
59
-				return $dataValueSerializer->serialize( $dataValue );
58
+			function($dataValue) use ($dataValueSerializer) {
59
+				return $dataValueSerializer->serialize($dataValue);
60 60
 			},
61 61
 			$comparisonResult->getExternalValues()
62 62
 		);
63
-		$this->setIndexedTagName( $externalValues, 'dataValue' );
63
+		$this->setIndexedTagName($externalValues, 'dataValue');
64 64
 
65 65
 		return [
66
-			'localValue' => $this->dataValueSerializer->serialize( $comparisonResult->getLocalValue() ),
66
+			'localValue' => $this->dataValueSerializer->serialize($comparisonResult->getLocalValue()),
67 67
 			'externalValues' => $externalValues,
68 68
 			'result' => $comparisonResult->getStatus()
69 69
 		];
Please login to merge, or discard this patch.
includes/Serializer/CrossCheckResultListSerializer.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	 */
19 19
 	private $crossCheckResultSerializer;
20 20
 
21
-	public function __construct( Serializer $crossCheckResultSerializer ) {
21
+	public function __construct(Serializer $crossCheckResultSerializer) {
22 22
 		$this->crossCheckResultSerializer = $crossCheckResultSerializer;
23 23
 	}
24 24
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @return bool
31 31
 	 */
32
-	public function isSerializerFor( $object ) {
32
+	public function isSerializerFor($object) {
33 33
 		return $object instanceof CrossCheckResultList;
34 34
 	}
35 35
 
@@ -41,29 +41,29 @@  discard block
 block discarded – undo
41 41
 	 * @return array
42 42
 	 * @throws UnsupportedObjectException
43 43
 	 */
44
-	public function serialize( $object ) {
45
-		if ( !$this->isSerializerFor( $object ) ) {
44
+	public function serialize($object) {
45
+		if (!$this->isSerializerFor($object)) {
46 46
 			throw new UnsupportedObjectException(
47 47
 				$object,
48 48
 				'CrossCheckResultListSerializer can only serialize CrossCheckResultList objects.'
49 49
 			);
50 50
 		}
51 51
 
52
-		return $this->getSerialized( $object );
52
+		return $this->getSerialized($object);
53 53
 	}
54 54
 
55
-	private function getSerialized( CrossCheckResultList $resultList ) {
55
+	private function getSerialized(CrossCheckResultList $resultList) {
56 56
 		$serialization = [];
57
-		$this->setKeyAttributeName( $serialization, 'property', 'id' );
57
+		$this->setKeyAttributeName($serialization, 'property', 'id');
58 58
 
59
-		foreach ( $resultList->getPropertyIds() as $propertyId ) {
59
+		foreach ($resultList->getPropertyIds() as $propertyId) {
60 60
 			$id = $propertyId->getSerialization();
61 61
 			$resultSerialization = [];
62 62
 
63
-			$this->setIndexedTagName( $resultSerialization, 'result' );
63
+			$this->setIndexedTagName($resultSerialization, 'result');
64 64
 
65
-			foreach ( $resultList->getByPropertyId( $propertyId ) as $result ) {
66
-				$resultSerialization[] = $this->crossCheckResultSerializer->serialize( $result );
65
+			foreach ($resultList->getByPropertyId($propertyId) as $result) {
66
+				$resultSerialization[] = $this->crossCheckResultSerializer->serialize($result);
67 67
 			}
68 68
 
69 69
 			$serialization[$id] = $resultSerialization;
Please login to merge, or discard this patch.
includes/Serializer/ReferenceResultSerializer.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	 */
19 19
 	private $referenceSerializer;
20 20
 
21
-	public function __construct( Serializer $referenceSerializer ) {
21
+	public function __construct(Serializer $referenceSerializer) {
22 22
 		$this->referenceSerializer = $referenceSerializer;
23 23
 	}
24 24
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @return bool
31 31
 	 */
32
-	public function isSerializerFor( $object ) {
32
+	public function isSerializerFor($object) {
33 33
 		return $object instanceof ReferenceResult;
34 34
 	}
35 35
 
@@ -41,20 +41,20 @@  discard block
 block discarded – undo
41 41
 	 * @return array
42 42
 	 * @throws UnsupportedObjectException
43 43
 	 */
44
-	public function serialize( $object ) {
45
-		if ( !$this->isSerializerFor( $object ) ) {
44
+	public function serialize($object) {
45
+		if (!$this->isSerializerFor($object)) {
46 46
 			throw new UnsupportedObjectException(
47 47
 				$object,
48 48
 				'ReferenceResultSerializer can only serialize ReferenceResult objects.'
49 49
 			);
50 50
 		}
51 51
 
52
-		return $this->getSerialized( $object );
52
+		return $this->getSerialized($object);
53 53
 	}
54 54
 
55
-	private function getSerialized( ReferenceResult $referenceResult ) {
55
+	private function getSerialized(ReferenceResult $referenceResult) {
56 56
 		return [
57
-			'reference' => $this->referenceSerializer->serialize( $referenceResult->getReference() ),
57
+			'reference' => $this->referenceSerializer->serialize($referenceResult->getReference()),
58 58
 			'status' => $referenceResult->getStatus()
59 59
 		];
60 60
 	}
Please login to merge, or discard this patch.