@@ -162,7 +162,7 @@ |
||
162 | 162 | /** |
163 | 163 | * Writes output for CrossCheckResultList |
164 | 164 | * |
165 | - * @param array $resultLists |
|
165 | + * @param \WikibaseQuality\ExternalValidation\CrossCheck\Result\CrossCheckResultList[] $resultLists |
|
166 | 166 | * |
167 | 167 | * @return array |
168 | 168 | */ |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return self |
67 | 67 | */ |
68 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
68 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
69 | 69 | $repo = WikibaseRepo::getDefaultInstance(); |
70 | 70 | $externalValidationServices = ExternalValidationServices::getDefaultInstance(); |
71 | 71 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | $repo->getStatementGuidValidator(), |
78 | 78 | $externalValidationServices->getCrossCheckInteractor(), |
79 | 79 | $externalValidationServices->getSerializerFactory(), |
80 | - $repo->getApiHelperFactory( RequestContext::getMain() ) |
|
80 | + $repo->getApiHelperFactory(RequestContext::getMain()) |
|
81 | 81 | ); |
82 | 82 | } |
83 | 83 | |
@@ -91,17 +91,17 @@ discard block |
||
91 | 91 | * @param SerializerFactory $serializerFactory |
92 | 92 | * @param ApiHelperFactory $apiHelperFactory |
93 | 93 | */ |
94 | - public function __construct( ApiMain $main, $name, $prefix = '', EntityIdParser $entityIdParser, |
|
94 | + public function __construct(ApiMain $main, $name, $prefix = '', EntityIdParser $entityIdParser, |
|
95 | 95 | StatementGuidValidator $statementGuidValidator, CrossCheckInteractor $crossCheckInteractor, |
96 | - SerializerFactory $serializerFactory, ApiHelperFactory $apiHelperFactory ) { |
|
97 | - parent::__construct( $main, $name, $prefix ); |
|
96 | + SerializerFactory $serializerFactory, ApiHelperFactory $apiHelperFactory) { |
|
97 | + parent::__construct($main, $name, $prefix); |
|
98 | 98 | |
99 | 99 | $this->entityIdParser = $entityIdParser; |
100 | 100 | $this->statementGuidValidator = $statementGuidValidator; |
101 | 101 | $this->crossCheckInteractor = $crossCheckInteractor; |
102 | 102 | $this->serializerFactory = $serializerFactory; |
103 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
104 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
103 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
104 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -110,24 +110,24 @@ discard block |
||
110 | 110 | public function execute() { |
111 | 111 | $params = $this->extractRequestParams(); |
112 | 112 | |
113 | - if ( $params['entities'] && $params['claims'] ) { |
|
113 | + if ($params['entities'] && $params['claims']) { |
|
114 | 114 | $this->errorReporter->dieError( |
115 | 115 | 'Either provide the ids of entities or ids of claims, that should be cross-checked.', |
116 | 116 | 'param-invalid' |
117 | 117 | ); |
118 | 118 | throw new LogicException(); |
119 | - } elseif ( $params['entities'] ) { |
|
120 | - $entityIds = $this->parseEntityIds( $params['entities'] ); |
|
121 | - if ( $params['properties'] ) { |
|
122 | - $propertyIds = $this->parseEntityIds( $params['properties'] ); |
|
123 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties( $entityIds, $propertyIds ); |
|
119 | + } elseif ($params['entities']) { |
|
120 | + $entityIds = $this->parseEntityIds($params['entities']); |
|
121 | + if ($params['properties']) { |
|
122 | + $propertyIds = $this->parseEntityIds($params['properties']); |
|
123 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties($entityIds, $propertyIds); |
|
124 | 124 | } else { |
125 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds( $entityIds ); |
|
125 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds($entityIds); |
|
126 | 126 | } |
127 | - } elseif ( $params['claims'] ) { |
|
127 | + } elseif ($params['claims']) { |
|
128 | 128 | $guids = $params['claims']; |
129 | - $this->assertAreValidClaimGuids( $guids ); |
|
130 | - $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids( $guids ); |
|
129 | + $this->assertAreValidClaimGuids($guids); |
|
130 | + $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids($guids); |
|
131 | 131 | } else { |
132 | 132 | $this->errorReporter->dieError( |
133 | 133 | 'Either provide the ids of entities or ids of claims, that should be cross-checked.', |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | } |
138 | 138 | |
139 | 139 | // Print result lists |
140 | - $this->writeResultOutput( $resultLists ); |
|
140 | + $this->writeResultOutput($resultLists); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return EntityId[] |
147 | 147 | */ |
148 | - private function parseEntityIds( array $entityIds ) { |
|
148 | + private function parseEntityIds(array $entityIds) { |
|
149 | 149 | return array_map( |
150 | - array( $this->entityIdParser, 'parse' ), |
|
150 | + array($this->entityIdParser, 'parse'), |
|
151 | 151 | $entityIds |
152 | 152 | ); |
153 | 153 | } |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | /** |
156 | 156 | * @param string[] $guids |
157 | 157 | */ |
158 | - private function assertAreValidClaimGuids( array $guids ) { |
|
159 | - foreach ( $guids as $guid ) { |
|
160 | - if ( $this->statementGuidValidator->validateFormat( $guid ) === false ) { |
|
161 | - $this->errorReporter->dieError( 'Invalid claim guid.', 'invalid-guid' ); |
|
158 | + private function assertAreValidClaimGuids(array $guids) { |
|
159 | + foreach ($guids as $guid) { |
|
160 | + if ($this->statementGuidValidator->validateFormat($guid) === false) { |
|
161 | + $this->errorReporter->dieError('Invalid claim guid.', 'invalid-guid'); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | } |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @return array |
172 | 172 | */ |
173 | - private function writeResultOutput( array $resultLists ) { |
|
173 | + private function writeResultOutput(array $resultLists) { |
|
174 | 174 | $serializer = $this->serializerFactory->newCrossCheckResultListSerializer(); |
175 | 175 | |
176 | 176 | $output = array(); |
177 | - foreach ( $resultLists as $entityId => $resultList ) { |
|
178 | - if ( $resultList ) { |
|
179 | - $serializedResultList = $serializer->serialize( $resultList ); |
|
177 | + foreach ($resultLists as $entityId => $resultList) { |
|
178 | + if ($resultList) { |
|
179 | + $serializedResultList = $serializer->serialize($resultList); |
|
180 | 180 | |
181 | 181 | $output[$entityId] = $serializedResultList; |
182 | 182 | } else { |
@@ -186,10 +186,10 @@ discard block |
||
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
189 | - $this->getResult()->setIndexedTagName( $output, 'entity' ); |
|
190 | - $this->getResult()->setArrayType( $output, 'kvp', 'id' ); |
|
191 | - $this->getResult()->addValue( null, 'results', $output ); |
|
192 | - $this->resultBuilder->markSuccess( 1 ); |
|
189 | + $this->getResult()->setIndexedTagName($output, 'entity'); |
|
190 | + $this->getResult()->setArrayType($output, 'kvp', 'id'); |
|
191 | + $this->getResult()->addValue(null, 'results', $output); |
|
192 | + $this->resultBuilder->markSuccess(1); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -288,7 +288,7 @@ |
||
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
291 | - * @param array $strings |
|
291 | + * @param string[] $strings |
|
292 | 292 | * @param string $parameterName |
293 | 293 | * |
294 | 294 | * @throws InvalidArgumentException |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param StatementGuidParser $statementGuidParser |
44 | 44 | * @param CrossChecker $crossChecker |
45 | 45 | */ |
46 | - public function __construct( EntityLookup $entityLookup, StatementGuidParser $statementGuidParser, CrossChecker $crossChecker ) { |
|
46 | + public function __construct(EntityLookup $entityLookup, StatementGuidParser $statementGuidParser, CrossChecker $crossChecker) { |
|
47 | 47 | $this->entityLookup = $entityLookup; |
48 | 48 | $this->statementGuidParser = $statementGuidParser; |
49 | 49 | $this->crossChecker = $crossChecker; |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @return CrossCheckResultList|null |
58 | 58 | */ |
59 | - public function crossCheckEntityById( EntityId $entityId ) { |
|
60 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
59 | + public function crossCheckEntityById(EntityId $entityId) { |
|
60 | + $entity = $this->entityLookup->getEntity($entityId); |
|
61 | 61 | |
62 | - if ( $entity instanceof StatementListProvider ) { |
|
63 | - return $this->crossCheckStatements( $entity->getStatements() ); |
|
62 | + if ($entity instanceof StatementListProvider) { |
|
63 | + return $this->crossCheckStatements($entity->getStatements()); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | return null; |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return CrossCheckResultList[] |
75 | 75 | */ |
76 | - public function crossCheckEntitiesByIds( array $entityIds ) { |
|
77 | - Assert::parameterElementType( EntityId::class, $entityIds, '$entityIds' ); |
|
76 | + public function crossCheckEntitiesByIds(array $entityIds) { |
|
77 | + Assert::parameterElementType(EntityId::class, $entityIds, '$entityIds'); |
|
78 | 78 | |
79 | 79 | $results = array(); |
80 | - foreach ( $entityIds as $entityId ) { |
|
81 | - $results[$entityId->getSerialization()] = $this->crossCheckEntityById( $entityId ); |
|
80 | + foreach ($entityIds as $entityId) { |
|
81 | + $results[$entityId->getSerialization()] = $this->crossCheckEntityById($entityId); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | return $results; |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return CrossCheckResultList |
93 | 93 | */ |
94 | - public function crossCheckStatements( StatementList $statements ) { |
|
95 | - return $this->crossChecker->crossCheckStatements( $statements, $statements ); |
|
94 | + public function crossCheckStatements(StatementList $statements) { |
|
95 | + return $this->crossChecker->crossCheckStatements($statements, $statements); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | * @return CrossCheckResultList[] |
104 | 104 | * @throws InvalidArgumentException |
105 | 105 | */ |
106 | - public function crossCheckEntities( array $entities ) { |
|
107 | - Assert::parameterElementType( EntityDocument::class, $entities, '$entities' ); |
|
106 | + public function crossCheckEntities(array $entities) { |
|
107 | + Assert::parameterElementType(EntityDocument::class, $entities, '$entities'); |
|
108 | 108 | |
109 | 109 | $results = array(); |
110 | - foreach ( $entities as $entity ) { |
|
110 | + foreach ($entities as $entity) { |
|
111 | 111 | $entityId = $entity->getId()->getSerialization(); |
112 | - if ( $entity instanceof StatementListProvider ) { |
|
113 | - $results[$entityId] = $this->crossCheckStatements( $entity->getStatements() ); |
|
112 | + if ($entity instanceof StatementListProvider) { |
|
113 | + $results[$entityId] = $this->crossCheckStatements($entity->getStatements()); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
@@ -126,13 +126,13 @@ discard block |
||
126 | 126 | * @return CrossCheckResultList|null |
127 | 127 | * @throws InvalidArgumentException |
128 | 128 | */ |
129 | - public function crossCheckEntityByIdWithProperties( EntityId $entityId, array $propertyIds ) { |
|
130 | - Assert::parameterElementType( PropertyId::class, $propertyIds, '$propertyIds' ); |
|
129 | + public function crossCheckEntityByIdWithProperties(EntityId $entityId, array $propertyIds) { |
|
130 | + Assert::parameterElementType(PropertyId::class, $propertyIds, '$propertyIds'); |
|
131 | 131 | |
132 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
132 | + $entity = $this->entityLookup->getEntity($entityId); |
|
133 | 133 | |
134 | - if ( $entity instanceof StatementListProvider ) { |
|
135 | - return $this->crossCheckStatementsWithProperties( $entity->getStatements(), $propertyIds ); |
|
134 | + if ($entity instanceof StatementListProvider) { |
|
135 | + return $this->crossCheckStatementsWithProperties($entity->getStatements(), $propertyIds); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | return null; |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | * @return CrossCheckResultList[] |
148 | 148 | * @throws InvalidArgumentException |
149 | 149 | */ |
150 | - public function crossCheckEntitiesByIdWithProperties( array $entityIds, array $propertyIds ) { |
|
151 | - Assert::parameterElementType( EntityId::class, $entityIds, '$entityIds' ); |
|
152 | - Assert::parameterElementType( PropertyId::class, $propertyIds, '$propertyIds' ); |
|
150 | + public function crossCheckEntitiesByIdWithProperties(array $entityIds, array $propertyIds) { |
|
151 | + Assert::parameterElementType(EntityId::class, $entityIds, '$entityIds'); |
|
152 | + Assert::parameterElementType(PropertyId::class, $propertyIds, '$propertyIds'); |
|
153 | 153 | |
154 | 154 | $results = array(); |
155 | - foreach ( $entityIds as $entityId ) { |
|
156 | - $results[$entityId->getSerialization()] = $this->crossCheckEntityByIdWithProperties( $entityId, $propertyIds ); |
|
155 | + foreach ($entityIds as $entityId) { |
|
156 | + $results[$entityId->getSerialization()] = $this->crossCheckEntityByIdWithProperties($entityId, $propertyIds); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | return $results; |
@@ -168,17 +168,17 @@ discard block |
||
168 | 168 | * @return CrossCheckResultList |
169 | 169 | * @throws InvalidArgumentException |
170 | 170 | */ |
171 | - public function crossCheckStatementsWithProperties( StatementList $entityStatements, array $propertyIds ) { |
|
172 | - Assert::parameterElementType( PropertyId::class, $propertyIds, '$propertyIds' ); |
|
171 | + public function crossCheckStatementsWithProperties(StatementList $entityStatements, array $propertyIds) { |
|
172 | + Assert::parameterElementType(PropertyId::class, $propertyIds, '$propertyIds'); |
|
173 | 173 | |
174 | 174 | $statements = new StatementList(); |
175 | - foreach ( $entityStatements->toArray() as $statement ) { |
|
176 | - if ( in_array( $statement->getPropertyId(), $propertyIds ) ) { |
|
177 | - $statements->addStatement( $statement ); |
|
175 | + foreach ($entityStatements->toArray() as $statement) { |
|
176 | + if (in_array($statement->getPropertyId(), $propertyIds)) { |
|
177 | + $statements->addStatement($statement); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - return $this->crossChecker->crossCheckStatements( $entityStatements, $statements ); |
|
181 | + return $this->crossChecker->crossCheckStatements($entityStatements, $statements); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | * @return CrossCheckResultList[] |
191 | 191 | * @throws InvalidArgumentException |
192 | 192 | */ |
193 | - public function crossCheckEntitiesWithProperties( array $entities, array $propertyIds ) { |
|
194 | - Assert::parameterElementType( EntityDocument::class, $entities, '$entities' ); |
|
195 | - Assert::parameterElementType( PropertyId::class, $propertyIds, '$propertyIds' ); |
|
193 | + public function crossCheckEntitiesWithProperties(array $entities, array $propertyIds) { |
|
194 | + Assert::parameterElementType(EntityDocument::class, $entities, '$entities'); |
|
195 | + Assert::parameterElementType(PropertyId::class, $propertyIds, '$propertyIds'); |
|
196 | 196 | |
197 | 197 | $results = array(); |
198 | - foreach ( $entities as $entity ) { |
|
198 | + foreach ($entities as $entity) { |
|
199 | 199 | $entityId = $entity->getId()->getSerialization(); |
200 | - if ( $entity instanceof StatementListProvider ) { |
|
200 | + if ($entity instanceof StatementListProvider) { |
|
201 | 201 | $results[$entityId] = $this->crossCheckStatementsWithProperties( |
202 | 202 | $entity->getStatements(), |
203 | 203 | $propertyIds |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | * @return CrossCheckResultList |
217 | 217 | * @throws InvalidArgumentException |
218 | 218 | */ |
219 | - public function crossCheckStatementByGuid( $guid ) { |
|
220 | - $this->assertIsString( $guid, '$guid' ); |
|
219 | + public function crossCheckStatementByGuid($guid) { |
|
220 | + $this->assertIsString($guid, '$guid'); |
|
221 | 221 | |
222 | - $resultList = $this->crossCheckStatementsByGuids( array( $guid ) ); |
|
222 | + $resultList = $this->crossCheckStatementsByGuids(array($guid)); |
|
223 | 223 | |
224 | - return reset( $resultList ); |
|
224 | + return reset($resultList); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -232,21 +232,21 @@ discard block |
||
232 | 232 | * @return CrossCheckResultList[] |
233 | 233 | * @throws InvalidArgumentException |
234 | 234 | */ |
235 | - public function crossCheckStatementsByGuids( array $guids ) { |
|
236 | - $this->assertIsArrayOfStrings( $guids, '$guids' ); |
|
235 | + public function crossCheckStatementsByGuids(array $guids) { |
|
236 | + $this->assertIsArrayOfStrings($guids, '$guids'); |
|
237 | 237 | |
238 | 238 | $entityIds = array(); |
239 | 239 | $groupedStatementGuids = array(); |
240 | - foreach ( $guids as $guid ) { |
|
241 | - $serializedEntityId = $this->statementGuidParser->parse( $guid )->getEntityId(); |
|
240 | + foreach ($guids as $guid) { |
|
241 | + $serializedEntityId = $this->statementGuidParser->parse($guid)->getEntityId(); |
|
242 | 242 | $entityIds[$serializedEntityId->getSerialization()] = $serializedEntityId; |
243 | 243 | $groupedStatementGuids[$serializedEntityId->getSerialization()][] = $guid; |
244 | 244 | } |
245 | 245 | |
246 | 246 | $resultLists = array(); |
247 | - foreach ( $groupedStatementGuids as $serializedEntityId => $guidsOfEntity ) { |
|
248 | - $entityId = $entityIds[ $serializedEntityId ]; |
|
249 | - $resultLists[ $serializedEntityId ] = $this->crossCheckClaimsOfEntity( $entityId, $guidsOfEntity ); |
|
247 | + foreach ($groupedStatementGuids as $serializedEntityId => $guidsOfEntity) { |
|
248 | + $entityId = $entityIds[$serializedEntityId]; |
|
249 | + $resultLists[$serializedEntityId] = $this->crossCheckClaimsOfEntity($entityId, $guidsOfEntity); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | return $resultLists; |
@@ -258,18 +258,18 @@ discard block |
||
258 | 258 | * |
259 | 259 | * @return CrossCheckResultList|null |
260 | 260 | */ |
261 | - private function crossCheckClaimsOfEntity( EntityId $entityId, array $guids ) { |
|
262 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
261 | + private function crossCheckClaimsOfEntity(EntityId $entityId, array $guids) { |
|
262 | + $entity = $this->entityLookup->getEntity($entityId); |
|
263 | 263 | |
264 | - if ( $entity instanceof StatementListProvider ) { |
|
264 | + if ($entity instanceof StatementListProvider) { |
|
265 | 265 | $statements = new StatementList(); |
266 | - foreach ( $entity->getStatements()->toArray() as $statement ) { |
|
267 | - if ( in_array( $statement->getGuid(), $guids ) ) { |
|
268 | - $statements->addStatement( $statement ); |
|
266 | + foreach ($entity->getStatements()->toArray() as $statement) { |
|
267 | + if (in_array($statement->getGuid(), $guids)) { |
|
268 | + $statements->addStatement($statement); |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
272 | - return $this->crossChecker->crossCheckStatements( $entity->getStatements(), $statements ); |
|
272 | + return $this->crossChecker->crossCheckStatements($entity->getStatements(), $statements); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | return null; |
@@ -281,9 +281,9 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @throws InvalidArgumentException |
283 | 283 | */ |
284 | - private function assertIsString( $string, $parameterName ) { |
|
285 | - if ( !is_string( $string ) ) { |
|
286 | - throw new InvalidArgumentException( "$parameterName must be string." ); |
|
284 | + private function assertIsString($string, $parameterName) { |
|
285 | + if (!is_string($string)) { |
|
286 | + throw new InvalidArgumentException("$parameterName must be string."); |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
@@ -293,10 +293,10 @@ discard block |
||
293 | 293 | * |
294 | 294 | * @throws InvalidArgumentException |
295 | 295 | */ |
296 | - private function assertIsArrayOfStrings( array $strings, $parameterName ) { |
|
297 | - foreach ( $strings as $string ) { |
|
298 | - if ( !is_string( $string ) ) { |
|
299 | - throw new InvalidArgumentException( "Each element of $parameterName must be string." ); |
|
296 | + private function assertIsArrayOfStrings(array $strings, $parameterName) { |
|
297 | + foreach ($strings as $string) { |
|
298 | + if (!is_string($string)) { |
|
299 | + throw new InvalidArgumentException("Each element of $parameterName must be string."); |
|
300 | 300 | } |
301 | 301 | } |
302 | 302 | } |
@@ -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 |
@@ -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 | } |