@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param string $prefix |
64 | 64 | * @return RunCrossCheck |
65 | 65 | */ |
66 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
66 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
67 | 67 | $repo = WikibaseRepo::getDefaultInstance(); |
68 | 68 | $externalValidationServices = ExternalValidationServices::getDefaultInstance(); |
69 | 69 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $repo->getStatementGuidValidator(), |
76 | 76 | $externalValidationServices->getCrossCheckInteractor(), |
77 | 77 | $externalValidationServices->getSerializerFactory(), |
78 | - $repo->getApiHelperFactory( RequestContext::getMain() ) |
|
78 | + $repo->getApiHelperFactory(RequestContext::getMain()) |
|
79 | 79 | ); |
80 | 80 | } |
81 | 81 | |
@@ -89,17 +89,17 @@ discard block |
||
89 | 89 | * @param SerializerFactory $serializerFactory |
90 | 90 | * @param ApiHelperFactory $apiHelperFactory |
91 | 91 | */ |
92 | - public function __construct( ApiMain $main, $name, $prefix = '', EntityIdParser $entityIdParser, |
|
92 | + public function __construct(ApiMain $main, $name, $prefix = '', EntityIdParser $entityIdParser, |
|
93 | 93 | StatementGuidValidator $statementGuidValidator, CrossCheckInteractor $crossCheckInteractor, |
94 | - SerializerFactory $serializerFactory, ApiHelperFactory $apiHelperFactory ) { |
|
95 | - parent::__construct( $main, $name, $prefix ); |
|
94 | + SerializerFactory $serializerFactory, ApiHelperFactory $apiHelperFactory) { |
|
95 | + parent::__construct($main, $name, $prefix); |
|
96 | 96 | |
97 | 97 | $this->entityIdParser = $entityIdParser; |
98 | 98 | $this->statementGuidValidator = $statementGuidValidator; |
99 | 99 | $this->crossCheckInteractor = $crossCheckInteractor; |
100 | 100 | $this->serializerFactory = $serializerFactory; |
101 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
102 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
101 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
102 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -108,23 +108,23 @@ discard block |
||
108 | 108 | public function execute() { |
109 | 109 | $params = $this->extractRequestParams(); |
110 | 110 | |
111 | - if ( $params['entities'] && $params['claims'] ) { |
|
111 | + if ($params['entities'] && $params['claims']) { |
|
112 | 112 | $this->errorReporter->dieError( |
113 | 113 | 'Either provide the ids of entities or ids of claims, that should be cross-checked.', |
114 | 114 | 'param-invalid' |
115 | 115 | ); |
116 | - } elseif ( $params['entities'] ) { |
|
117 | - $entityIds = $this->parseEntityIds( $params['entities'] ); |
|
118 | - if ( $params['properties'] ) { |
|
119 | - $propertyIds = $this->parseEntityIds( $params['properties'] ); |
|
120 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties( $entityIds, $propertyIds ); |
|
116 | + } elseif ($params['entities']) { |
|
117 | + $entityIds = $this->parseEntityIds($params['entities']); |
|
118 | + if ($params['properties']) { |
|
119 | + $propertyIds = $this->parseEntityIds($params['properties']); |
|
120 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties($entityIds, $propertyIds); |
|
121 | 121 | } else { |
122 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds( $entityIds ); |
|
122 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds($entityIds); |
|
123 | 123 | } |
124 | - } elseif ( $params['claims'] ) { |
|
124 | + } elseif ($params['claims']) { |
|
125 | 125 | $guids = $params['claims']; |
126 | - $this->assertAreValidClaimGuids( $guids ); |
|
127 | - $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids( $guids ); |
|
126 | + $this->assertAreValidClaimGuids($guids); |
|
127 | + $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids($guids); |
|
128 | 128 | } else { |
129 | 129 | $this->errorReporter->dieError( |
130 | 130 | 'Either provide the ids of entities or ids of claims, that should be cross-checked.', |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | // Print result lists |
136 | - $this->writeResultOutput( $resultLists ); |
|
136 | + $this->writeResultOutput($resultLists); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return EntityId[] |
143 | 143 | */ |
144 | - private function parseEntityIds( array $entityIds ) { |
|
144 | + private function parseEntityIds(array $entityIds) { |
|
145 | 145 | return array_map( |
146 | - array( $this->entityIdParser, 'parse' ), |
|
146 | + array($this->entityIdParser, 'parse'), |
|
147 | 147 | $entityIds |
148 | 148 | ); |
149 | 149 | } |
@@ -151,10 +151,10 @@ discard block |
||
151 | 151 | /** |
152 | 152 | * @param string[] $guids |
153 | 153 | */ |
154 | - private function assertAreValidClaimGuids( array $guids ) { |
|
155 | - foreach ( $guids as $guid ) { |
|
156 | - if ( $this->statementGuidValidator->validateFormat( $guid ) === false ) { |
|
157 | - $this->errorReporter->dieError( 'Invalid claim guid.', 'invalid-guid' ); |
|
154 | + private function assertAreValidClaimGuids(array $guids) { |
|
155 | + foreach ($guids as $guid) { |
|
156 | + if ($this->statementGuidValidator->validateFormat($guid) === false) { |
|
157 | + $this->errorReporter->dieError('Invalid claim guid.', 'invalid-guid'); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
@@ -166,13 +166,13 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @return array |
168 | 168 | */ |
169 | - private function writeResultOutput( array $resultLists ) { |
|
169 | + private function writeResultOutput(array $resultLists) { |
|
170 | 170 | $serializer = $this->serializerFactory->newCrossCheckResultListSerializer(); |
171 | 171 | |
172 | 172 | $output = array(); |
173 | - foreach ( $resultLists as $entityId => $resultList ) { |
|
174 | - if ( $resultList ) { |
|
175 | - $serializedResultList = $serializer->serialize( $resultList ); |
|
173 | + foreach ($resultLists as $entityId => $resultList) { |
|
174 | + if ($resultList) { |
|
175 | + $serializedResultList = $serializer->serialize($resultList); |
|
176 | 176 | |
177 | 177 | $output[$entityId] = $serializedResultList; |
178 | 178 | } else { |
@@ -182,10 +182,10 @@ discard block |
||
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
185 | - $this->getResult()->setIndexedTagName( $output, 'entity' ); |
|
186 | - $this->getResult()->setArrayType( $output, 'kvp', 'id' ); |
|
187 | - $this->getResult()->addValue( null, 'results', $output ); |
|
188 | - $this->resultBuilder->markSuccess( 1 ); |
|
185 | + $this->getResult()->setIndexedTagName($output, 'entity'); |
|
186 | + $this->getResult()->setArrayType($output, 'kvp', 'id'); |
|
187 | + $this->getResult()->addValue(null, 'results', $output); |
|
188 | + $this->resultBuilder->markSuccess(1); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return bool |
20 | 20 | */ |
21 | - public function canCompare( DataValue $value, DataValue $comparativeValue ); |
|
21 | + public function canCompare(DataValue $value, DataValue $comparativeValue); |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Runs the comparison of two DataValues. |
@@ -28,6 +28,6 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string One of the ComparisonResult::STATUS_... constants. |
30 | 30 | */ |
31 | - public function compare( DataValue $value, DataValue $comparativeValue ); |
|
31 | + public function compare(DataValue $value, DataValue $comparativeValue); |
|
32 | 32 | |
33 | 33 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param TermIndex $termIndex |
27 | 27 | * @param StringNormalizer $stringNormalizer |
28 | 28 | */ |
29 | - public function __construct( TermIndex $termIndex, StringNormalizer $stringNormalizer ) { |
|
29 | + public function __construct(TermIndex $termIndex, StringNormalizer $stringNormalizer) { |
|
30 | 30 | $this->termIndex = $termIndex; |
31 | 31 | $this->stringNormalizer = $stringNormalizer; |
32 | 32 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return StringComparer |
69 | 69 | */ |
70 | 70 | private function newStringComparer() { |
71 | - return new StringComparer( $this->stringNormalizer ); |
|
71 | + return new StringComparer($this->stringNormalizer); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * @param DataValueComparer[] $dataValueComparers |
22 | 22 | */ |
23 | - public function __construct( array $dataValueComparers = array() ) { |
|
24 | - $this->assertAreDataValueComparer( $dataValueComparers ); |
|
23 | + public function __construct(array $dataValueComparers = array()) { |
|
24 | + $this->assertAreDataValueComparer($dataValueComparers); |
|
25 | 25 | $this->dataValueComparers = $dataValueComparers; |
26 | 26 | } |
27 | 27 | |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @throws InvalidArgumentException |
32 | 32 | */ |
33 | - protected function assertAreDataValueComparer( array $dataValueComparers ) { |
|
34 | - foreach ( $dataValueComparers as $dataValueComparer ) { |
|
35 | - if ( !is_object( $dataValueComparer ) || !( $dataValueComparer instanceof DataValueComparer ) ) { |
|
33 | + protected function assertAreDataValueComparer(array $dataValueComparers) { |
|
34 | + foreach ($dataValueComparers as $dataValueComparer) { |
|
35 | + if (!is_object($dataValueComparer) || !($dataValueComparer instanceof DataValueComparer)) { |
|
36 | 36 | throw new InvalidArgumentException( |
37 | 37 | 'All $dataValueComparers need to implement the DataValueComparer interface' |
38 | 38 | ); |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return bool |
50 | 50 | */ |
51 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
52 | - foreach ( $this->dataValueComparers as $dataValueComparer ) { |
|
53 | - if ( $dataValueComparer->canCompare( $value, $comparativeValue ) ) { |
|
51 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
52 | + foreach ($this->dataValueComparers as $dataValueComparer) { |
|
53 | + if ($dataValueComparer->canCompare($value, $comparativeValue)) { |
|
54 | 54 | return true; |
55 | 55 | } |
56 | 56 | } |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | * @throws InvalidArgumentException |
68 | 68 | * @return string One of the ComparisonResult::STATUS_... constants. |
69 | 69 | */ |
70 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
71 | - foreach ( $this->dataValueComparers as $dataValueComparer ) { |
|
72 | - if ( $dataValueComparer->canCompare( $value, $comparativeValue ) ) { |
|
73 | - return $dataValueComparer->compare( $value, $comparativeValue ); |
|
70 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
71 | + foreach ($this->dataValueComparers as $dataValueComparer) { |
|
72 | + if ($dataValueComparer->canCompare($value, $comparativeValue)) { |
|
73 | + return $dataValueComparer->compare($value, $comparativeValue); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 |
@@ -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 | /** |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | $extLat = $comparativeValue->getLatitude(); |
40 | 40 | $extLong = $comparativeValue->getLongitude(); |
41 | 41 | |
42 | - $diffLat = abs( $locLat - $extLat ); |
|
43 | - $diffLong = abs( $locLong - $extLong ); |
|
44 | - if ( ( $diffLat <= $precision ) && ( $diffLong <= $precision ) ) { |
|
42 | + $diffLat = abs($locLat - $extLat); |
|
43 | + $diffLong = abs($locLong - $extLong); |
|
44 | + if (($diffLat <= $precision) && ($diffLong <= $precision)) { |
|
45 | 45 | return ComparisonResult::STATUS_MATCH; |
46 | 46 | } |
47 | 47 | |
48 | 48 | $daumen = $precision; |
49 | - if ( ( $diffLat <= pi() * $daumen ) && ( $diffLong <= pi() * $daumen ) ) { |
|
49 | + if (($diffLat <= pi() * $daumen) && ($diffLong <= pi() * $daumen)) { |
|
50 | 50 | return ComparisonResult::STATUS_PARTIAL_MATCH; |
51 | 51 | } |
52 | 52 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param DataValue $comparativeValue |
61 | 61 | * @return bool |
62 | 62 | */ |
63 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
63 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
64 | 64 | return $value instanceof GlobeCoordinateValue && $comparativeValue instanceof GlobeCoordinateValue; |
65 | 65 | } |
66 | 66 |
@@ -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 | } |