@@ -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 | |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | SerializerFactory $serializerFactory, |
102 | 102 | ApiHelperFactory $apiHelperFactory |
103 | 103 | ) { |
104 | - parent::__construct( $main, $name, $prefix ); |
|
104 | + parent::__construct($main, $name, $prefix); |
|
105 | 105 | |
106 | 106 | $this->entityIdParser = $entityIdParser; |
107 | 107 | $this->statementGuidValidator = $statementGuidValidator; |
108 | 108 | $this->crossCheckInteractor = $crossCheckInteractor; |
109 | 109 | $this->serializerFactory = $serializerFactory; |
110 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
111 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
110 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
111 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -117,24 +117,24 @@ discard block |
||
117 | 117 | public function execute() { |
118 | 118 | $params = $this->extractRequestParams(); |
119 | 119 | |
120 | - if ( $params['entities'] && $params['claims'] ) { |
|
120 | + if ($params['entities'] && $params['claims']) { |
|
121 | 121 | $this->errorReporter->dieError( |
122 | 122 | 'Either provide the ids of entities or ids of claims, that should be cross-checked.', |
123 | 123 | 'param-invalid' |
124 | 124 | ); |
125 | 125 | throw new LogicException(); |
126 | - } elseif ( $params['entities'] ) { |
|
127 | - $entityIds = $this->parseEntityIds( $params['entities'] ); |
|
128 | - if ( $params['properties'] ) { |
|
129 | - $propertyIds = $this->parseEntityIds( $params['properties'] ); |
|
130 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties( $entityIds, $propertyIds ); |
|
126 | + } elseif ($params['entities']) { |
|
127 | + $entityIds = $this->parseEntityIds($params['entities']); |
|
128 | + if ($params['properties']) { |
|
129 | + $propertyIds = $this->parseEntityIds($params['properties']); |
|
130 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties($entityIds, $propertyIds); |
|
131 | 131 | } else { |
132 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds( $entityIds ); |
|
132 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds($entityIds); |
|
133 | 133 | } |
134 | - } elseif ( $params['claims'] ) { |
|
134 | + } elseif ($params['claims']) { |
|
135 | 135 | $guids = $params['claims']; |
136 | - $this->assertAreValidClaimGuids( $guids ); |
|
137 | - $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids( $guids ); |
|
136 | + $this->assertAreValidClaimGuids($guids); |
|
137 | + $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids($guids); |
|
138 | 138 | } else { |
139 | 139 | $this->errorReporter->dieError( |
140 | 140 | 'Either provide the ids of entities or ids of claims, that should be cross-checked.', |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | // Print result lists |
147 | - $this->writeResultOutput( $resultLists ); |
|
147 | + $this->writeResultOutput($resultLists); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return EntityId[] |
154 | 154 | */ |
155 | - private function parseEntityIds( array $entityIds ) { |
|
155 | + private function parseEntityIds(array $entityIds) { |
|
156 | 156 | return array_map( |
157 | - [ $this->entityIdParser, 'parse' ], |
|
157 | + [$this->entityIdParser, 'parse'], |
|
158 | 158 | $entityIds |
159 | 159 | ); |
160 | 160 | } |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | /** |
163 | 163 | * @param string[] $guids |
164 | 164 | */ |
165 | - private function assertAreValidClaimGuids( array $guids ) { |
|
166 | - foreach ( $guids as $guid ) { |
|
167 | - if ( $this->statementGuidValidator->validateFormat( $guid ) === false ) { |
|
168 | - $this->errorReporter->dieError( 'Invalid claim guid.', 'invalid-guid' ); |
|
165 | + private function assertAreValidClaimGuids(array $guids) { |
|
166 | + foreach ($guids as $guid) { |
|
167 | + if ($this->statementGuidValidator->validateFormat($guid) === false) { |
|
168 | + $this->errorReporter->dieError('Invalid claim guid.', 'invalid-guid'); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | } |
@@ -177,13 +177,13 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return array |
179 | 179 | */ |
180 | - private function writeResultOutput( array $resultLists ) { |
|
180 | + private function writeResultOutput(array $resultLists) { |
|
181 | 181 | $serializer = $this->serializerFactory->newCrossCheckResultListSerializer(); |
182 | 182 | |
183 | 183 | $output = []; |
184 | - foreach ( $resultLists as $entityId => $resultList ) { |
|
185 | - if ( $resultList ) { |
|
186 | - $serializedResultList = $serializer->serialize( $resultList ); |
|
184 | + foreach ($resultLists as $entityId => $resultList) { |
|
185 | + if ($resultList) { |
|
186 | + $serializedResultList = $serializer->serialize($resultList); |
|
187 | 187 | |
188 | 188 | $output[$entityId] = $serializedResultList; |
189 | 189 | } else { |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - $this->getResult()->setIndexedTagName( $output, 'entity' ); |
|
197 | - $this->getResult()->setArrayType( $output, 'kvp', 'id' ); |
|
198 | - $this->getResult()->addValue( null, 'results', $output ); |
|
199 | - $this->resultBuilder->markSuccess( 1 ); |
|
196 | + $this->getResult()->setIndexedTagName($output, 'entity'); |
|
197 | + $this->getResult()->setArrayType($output, 'kvp', 'id'); |
|
198 | + $this->getResult()->addValue(null, 'results', $output); |
|
199 | + $this->resultBuilder->markSuccess(1); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -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 = []; |
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 = []; |
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 = []; |
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 = []; |
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( [ $guid ] ); |
|
222 | + $resultList = $this->crossCheckStatementsByGuids([$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 = []; |
239 | 239 | $groupedStatementGuids = []; |
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 = []; |
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 | /** |
@@ -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 |
@@ -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 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @param StringNormalizer $stringNormalizer |
19 | 19 | */ |
20 | - public function __construct( StringNormalizer $stringNormalizer ) { |
|
20 | + public function __construct(StringNormalizer $stringNormalizer) { |
|
21 | 21 | $this->stringNormalizer = $stringNormalizer; |
22 | 22 | } |
23 | 23 | |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return StringValue |
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 | - return new StringValue( $this->stringNormalizer->trimToNFC( $value ) ); |
|
34 | + return new StringValue($this->stringNormalizer->trimToNFC($value)); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | } |