@@ -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 | } |
@@ -95,22 +95,22 @@ discard block |
||
| 95 | 95 | * @return CrossCheckResultList |
| 96 | 96 | * @throws InvalidArgumentException |
| 97 | 97 | */ |
| 98 | - public function crossCheckStatements( StatementList $entityStatements, StatementList $statements ) { |
|
| 98 | + public function crossCheckStatements(StatementList $entityStatements, StatementList $statements) { |
|
| 99 | 99 | $statementsOfEntity = $entityStatements->toArray(); |
| 100 | 100 | |
| 101 | - foreach ( $statements as $statement ) { |
|
| 102 | - if ( !in_array( $statement, $statementsOfEntity ) ) { |
|
| 103 | - throw new InvalidArgumentException( 'All statements in $statements must belong to the entity.' ); |
|
| 101 | + foreach ($statements as $statement) { |
|
| 102 | + if (!in_array($statement, $statementsOfEntity)) { |
|
| 103 | + throw new InvalidArgumentException('All statements in $statements must belong to the entity.'); |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $resultList = new CrossCheckResultList(); |
| 108 | - if ( $statements->count() > 0 ) { |
|
| 109 | - $applicableDumps = $this->getApplicableDumps( $entityStatements ); |
|
| 110 | - foreach ( $applicableDumps as $identifierPropertyId => $dumpMetaInformationList ) { |
|
| 111 | - $identifierPropertyId = new PropertyId( $identifierPropertyId ); |
|
| 108 | + if ($statements->count() > 0) { |
|
| 109 | + $applicableDumps = $this->getApplicableDumps($entityStatements); |
|
| 110 | + foreach ($applicableDumps as $identifierPropertyId => $dumpMetaInformationList) { |
|
| 111 | + $identifierPropertyId = new PropertyId($identifierPropertyId); |
|
| 112 | 112 | |
| 113 | - if ( $this->isIdentifierProperty( $identifierPropertyId ) ) { |
|
| 113 | + if ($this->isIdentifierProperty($identifierPropertyId)) { |
|
| 114 | 114 | $resultList->merge( |
| 115 | 115 | $this->crossCheckStatementsWithIdentifier( |
| 116 | 116 | $entityStatements, |
@@ -133,17 +133,17 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @return array[] |
| 135 | 135 | */ |
| 136 | - private function getApplicableDumps( StatementList $statements ) { |
|
| 136 | + private function getApplicableDumps(StatementList $statements) { |
|
| 137 | 137 | $applicableDumps = []; |
| 138 | 138 | $identifierPropertyIds = $statements->getPropertyIds(); |
| 139 | 139 | $dumpMetaInformation = $this->dumpMetaInformationLookup->getWithIdentifierProperties( |
| 140 | 140 | $identifierPropertyIds |
| 141 | 141 | ); |
| 142 | 142 | |
| 143 | - foreach ( $dumpMetaInformation as $dump ) { |
|
| 144 | - foreach ( $dump->getIdentifierPropertyIds() as $identifierPropertyId ) { |
|
| 143 | + foreach ($dumpMetaInformation as $dump) { |
|
| 144 | + foreach ($dump->getIdentifierPropertyIds() as $identifierPropertyId) { |
|
| 145 | 145 | $serialization = $identifierPropertyId->getSerialization(); |
| 146 | - $applicableDumps[ $serialization ][ $dump->getDumpId() ] = $dump; |
|
| 146 | + $applicableDumps[$serialization][$dump->getDumpId()] = $dump; |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
@@ -168,36 +168,36 @@ discard block |
||
| 168 | 168 | ) { |
| 169 | 169 | $resultList = new CrossCheckResultList(); |
| 170 | 170 | |
| 171 | - $externalIds = $this->getExternalIds( $entityStatements, $identifierPropertyId ); |
|
| 172 | - if ( !$externalIds ) { |
|
| 171 | + $externalIds = $this->getExternalIds($entityStatements, $identifierPropertyId); |
|
| 172 | + if (!$externalIds) { |
|
| 173 | 173 | return $resultList; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | $dumpIds = array_map( |
| 177 | - function ( DumpMetaInformation $dumpMetaInformation ) { |
|
| 177 | + function(DumpMetaInformation $dumpMetaInformation) { |
|
| 178 | 178 | return $dumpMetaInformation->getDumpId(); |
| 179 | 179 | }, |
| 180 | 180 | $dumpMetaInformationList |
| 181 | 181 | ); |
| 182 | - $externalData = $this->externalDataRepo->getExternalData( $dumpIds, $externalIds, $statements->getPropertyIds() ); |
|
| 182 | + $externalData = $this->externalDataRepo->getExternalData($dumpIds, $externalIds, $statements->getPropertyIds()); |
|
| 183 | 183 | |
| 184 | - foreach ( $externalData as $dumpId => $externalDataPerDump ) { |
|
| 185 | - $dumpMetaInformation = $dumpMetaInformationList[ $dumpId ]; |
|
| 184 | + foreach ($externalData as $dumpId => $externalDataPerDump) { |
|
| 185 | + $dumpMetaInformation = $dumpMetaInformationList[$dumpId]; |
|
| 186 | 186 | $comparativeValueParser = $this->valueParserFactory->newComparativeValueParser( |
| 187 | 187 | $dumpMetaInformation->getLanguageCode() |
| 188 | 188 | ); |
| 189 | 189 | |
| 190 | - foreach ( $externalDataPerDump as $externalId => $externalDataPerId ) { |
|
| 190 | + foreach ($externalDataPerDump as $externalId => $externalDataPerId) { |
|
| 191 | 191 | $externalId = (string)$externalId; |
| 192 | - foreach ( $externalDataPerId as $propertyId => $externalValues ) { |
|
| 193 | - $propertyId = new PropertyId( $propertyId ); |
|
| 192 | + foreach ($externalDataPerId as $propertyId => $externalValues) { |
|
| 193 | + $propertyId = new PropertyId($propertyId); |
|
| 194 | 194 | $resultList->merge( |
| 195 | 195 | $this->crossCheckExternalValues( |
| 196 | 196 | $dumpMetaInformation, |
| 197 | 197 | $identifierPropertyId, |
| 198 | 198 | $externalId, |
| 199 | 199 | $externalValues, |
| 200 | - $statements->getByPropertyId( $propertyId ), |
|
| 200 | + $statements->getByPropertyId($propertyId), |
|
| 201 | 201 | $comparativeValueParser |
| 202 | 202 | ) |
| 203 | 203 | ); |
@@ -228,10 +228,10 @@ discard block |
||
| 228 | 228 | ) { |
| 229 | 229 | $resultList = new CrossCheckResultList(); |
| 230 | 230 | |
| 231 | - foreach ( $statements->toArray() as $statement ) { |
|
| 232 | - $comparisonResult = $this->compareStatement( $statement, $externalValues, $comparativeValueParser ); |
|
| 231 | + foreach ($statements->toArray() as $statement) { |
|
| 232 | + $comparisonResult = $this->compareStatement($statement, $externalValues, $comparativeValueParser); |
|
| 233 | 233 | |
| 234 | - if ( $comparisonResult ) { |
|
| 234 | + if ($comparisonResult) { |
|
| 235 | 235 | $referencesResult = $this->referenceHandler->checkForReferences( |
| 236 | 236 | $statement, |
| 237 | 237 | $identifierPropertyId, |
@@ -265,31 +265,31 @@ discard block |
||
| 265 | 265 | * @return ComparisonResult|bool |
| 266 | 266 | */ |
| 267 | 267 | private function compareStatement( |
| 268 | - Statement $statement,array $externalValues, |
|
| 268 | + Statement $statement, array $externalValues, |
|
| 269 | 269 | ComparativeValueParser $comparativeValueParser |
| 270 | 270 | ) { |
| 271 | 271 | $mainSnak = $statement->getMainSnak(); |
| 272 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
| 272 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
| 273 | 273 | $dataValue = $mainSnak->getDataValue(); |
| 274 | 274 | |
| 275 | 275 | $results = []; |
| 276 | - $comparativeValues = $this->parseExternalValues( $dataValue, $externalValues, $comparativeValueParser ); |
|
| 277 | - foreach ( $comparativeValues as $comparativeValue ) { |
|
| 278 | - $result = $this->dataValueComparer->compare( $dataValue, $comparativeValue ); |
|
| 279 | - if ( $result ) { |
|
| 276 | + $comparativeValues = $this->parseExternalValues($dataValue, $externalValues, $comparativeValueParser); |
|
| 277 | + foreach ($comparativeValues as $comparativeValue) { |
|
| 278 | + $result = $this->dataValueComparer->compare($dataValue, $comparativeValue); |
|
| 279 | + if ($result) { |
|
| 280 | 280 | $results[] = $result; |
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - if ( $results ) { |
|
| 284 | + if ($results) { |
|
| 285 | 285 | $result = ComparisonResult::STATUS_MISMATCH; |
| 286 | - if ( in_array( ComparisonResult::STATUS_MATCH, $results ) ) { |
|
| 286 | + if (in_array(ComparisonResult::STATUS_MATCH, $results)) { |
|
| 287 | 287 | $result = ComparisonResult::STATUS_MATCH; |
| 288 | - } elseif ( in_array( ComparisonResult::STATUS_PARTIAL_MATCH, $results ) ) { |
|
| 288 | + } elseif (in_array(ComparisonResult::STATUS_PARTIAL_MATCH, $results)) { |
|
| 289 | 289 | $result = ComparisonResult::STATUS_PARTIAL_MATCH; |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - return new ComparisonResult( $dataValue, $comparativeValues, $result ); |
|
| 292 | + return new ComparisonResult($dataValue, $comparativeValues, $result); |
|
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | |
@@ -309,13 +309,13 @@ discard block |
||
| 309 | 309 | ComparativeValueParser $comparativeValueParser |
| 310 | 310 | ) { |
| 311 | 311 | $parsedValues = []; |
| 312 | - foreach ( $externalValues as $externalValue ) { |
|
| 312 | + foreach ($externalValues as $externalValue) { |
|
| 313 | 313 | try { |
| 314 | - $parsedValue = $comparativeValueParser->parse( $externalValue, $dataValue->getType() ); |
|
| 315 | - if ( $parsedValue ) { |
|
| 314 | + $parsedValue = $comparativeValueParser->parse($externalValue, $dataValue->getType()); |
|
| 315 | + if ($parsedValue) { |
|
| 316 | 316 | $parsedValues[] = $parsedValue; |
| 317 | 317 | } |
| 318 | - } catch ( ParseException $e ) { |
|
| 318 | + } catch (ParseException $e) { |
|
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | |
@@ -330,12 +330,12 @@ discard block |
||
| 330 | 330 | * |
| 331 | 331 | * @return string[] |
| 332 | 332 | */ |
| 333 | - private function getExternalIds( StatementList $statements, PropertyId $identifierPropertyId ) { |
|
| 333 | + private function getExternalIds(StatementList $statements, PropertyId $identifierPropertyId) { |
|
| 334 | 334 | $externalIds = []; |
| 335 | - $identifierStatements = $statements->getByPropertyId( $identifierPropertyId ); |
|
| 336 | - $values = $this->getDataValues( $identifierStatements ); |
|
| 337 | - foreach ( $values as $value ) { |
|
| 338 | - if ( $value instanceof StringValue ) { |
|
| 335 | + $identifierStatements = $statements->getByPropertyId($identifierPropertyId); |
|
| 336 | + $values = $this->getDataValues($identifierStatements); |
|
| 337 | + foreach ($values as $value) { |
|
| 338 | + if ($value instanceof StringValue) { |
|
| 339 | 339 | $externalIds[] = $value->getValue(); |
| 340 | 340 | } |
| 341 | 341 | } |
@@ -347,15 +347,15 @@ discard block |
||
| 347 | 347 | * @param PropertyId $identifierPropertyId |
| 348 | 348 | * @return bool |
| 349 | 349 | */ |
| 350 | - private function isIdentifierProperty( PropertyId $identifierPropertyId ) { |
|
| 350 | + private function isIdentifierProperty(PropertyId $identifierPropertyId) { |
|
| 351 | 351 | global $wgWBQEVInstanceOfPID, $wgWBQEVIdentifierPropertyQID; |
| 352 | 352 | /** @var Property $property */ |
| 353 | - $property = $this->entityLookup->getEntity( $identifierPropertyId ); |
|
| 354 | - $instanceOfPropertyId = new PropertyId( $wgWBQEVInstanceOfPID ); |
|
| 355 | - $statements = $property->getStatements()->getByPropertyId( $instanceOfPropertyId ); |
|
| 356 | - $values = $this->getDataValues( $statements ); |
|
| 357 | - foreach ( $values as $value ) { |
|
| 358 | - if ( $value instanceof EntityIdValue |
|
| 353 | + $property = $this->entityLookup->getEntity($identifierPropertyId); |
|
| 354 | + $instanceOfPropertyId = new PropertyId($wgWBQEVInstanceOfPID); |
|
| 355 | + $statements = $property->getStatements()->getByPropertyId($instanceOfPropertyId); |
|
| 356 | + $values = $this->getDataValues($statements); |
|
| 357 | + foreach ($values as $value) { |
|
| 358 | + if ($value instanceof EntityIdValue |
|
| 359 | 359 | && $value->getEntityId()->getSerialization() === $wgWBQEVIdentifierPropertyQID |
| 360 | 360 | ) { |
| 361 | 361 | return true; |
@@ -371,12 +371,12 @@ discard block |
||
| 371 | 371 | * @param StatementList $statementList |
| 372 | 372 | * @return DataValue[] |
| 373 | 373 | */ |
| 374 | - private function getDataValues( StatementList $statementList ) { |
|
| 374 | + private function getDataValues(StatementList $statementList) { |
|
| 375 | 375 | $dataValues = []; |
| 376 | 376 | |
| 377 | - foreach ( $statementList->toArray() as $statement ) { |
|
| 377 | + foreach ($statementList->toArray() as $statement) { |
|
| 378 | 378 | $mainSnak = $statement->getMainSnak(); |
| 379 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
| 379 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
| 380 | 380 | $dataValues[] = $mainSnak->getDataValue(); |
| 381 | 381 | } |
| 382 | 382 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * @param ValueParser $monolingualTextValueParser |
| 23 | 23 | */ |
| 24 | - public function __construct( ValueParser $monolingualTextValueParser ) { |
|
| 24 | + public function __construct(ValueParser $monolingualTextValueParser) { |
|
| 25 | 25 | $this->monolingualTextValueParser = $monolingualTextValueParser; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @return MultilingualTextValue |
| 34 | 34 | */ |
| 35 | - public function parse( $value ) { |
|
| 36 | - Assert::parameterType( 'string', $value, '$value' ); |
|
| 35 | + public function parse($value) { |
|
| 36 | + Assert::parameterType('string', $value, '$value'); |
|
| 37 | 37 | |
| 38 | 38 | return new MultilingualTextValue( |
| 39 | - [ $this->monolingualTextValueParser->parse( $value ) ] |
|
| 39 | + [$this->monolingualTextValueParser->parse($value)] |
|
| 40 | 40 | ); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | ) { |
| 44 | 44 | $dataTypeIds = $dataTypeDefinitions->getTypeIds(); |
| 45 | 45 | |
| 46 | - if ( !in_array( 'monolingualtext', $dataTypeIds ) ) { |
|
| 46 | + if (!in_array('monolingualtext', $dataTypeIds)) { |
|
| 47 | 47 | throw new InvalidArgumentException( |
| 48 | 48 | 'monolingualtext must be defined in the DataTypeDefinitions.' |
| 49 | 49 | ); |
@@ -58,21 +58,21 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @return MultilingualTextValueParser |
| 60 | 60 | */ |
| 61 | - public function newMultilingualTextValueParser( ParserOptions $options = null ) { |
|
| 61 | + public function newMultilingualTextValueParser(ParserOptions $options = null) { |
|
| 62 | 62 | $options = $options ?: new ParserOptions(); |
| 63 | 63 | $monolingualTextValueParser = $this->getValueParserFactory()->newParser( |
| 64 | 64 | 'monolingualtext', |
| 65 | 65 | $options |
| 66 | 66 | ); |
| 67 | 67 | |
| 68 | - return new MultilingualTextValueParser( $monolingualTextValueParser ); |
|
| 68 | + return new MultilingualTextValueParser($monolingualTextValueParser); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * @return StringValueParser |
| 73 | 73 | */ |
| 74 | 74 | public function newStringValueParser() { |
| 75 | - return new StringValueParser( $this->stringNormalizer ); |
|
| 75 | + return new StringValueParser($this->stringNormalizer); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return ComparativeValueParser |
| 82 | 82 | */ |
| 83 | - public function newComparativeValueParser( $languageCode ) { |
|
| 84 | - Assert::parameterType( 'string', $languageCode, '$languageCode' ); |
|
| 83 | + public function newComparativeValueParser($languageCode) { |
|
| 84 | + Assert::parameterType('string', $languageCode, '$languageCode'); |
|
| 85 | 85 | |
| 86 | 86 | return new ComparativeValueParser( |
| 87 | 87 | $this->getValueParserFactory(), |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | * @return ValueParserFactory |
| 101 | 101 | */ |
| 102 | 102 | private function getValueParserFactory() { |
| 103 | - if ( $this->valueParserFactory === null ) { |
|
| 103 | + if ($this->valueParserFactory === null) { |
|
| 104 | 104 | $callbacks = $this->dataTypeDefinitions->getParserFactoryCallbacks(); |
| 105 | 105 | |
| 106 | - $callbacks['string'] = [ $this, 'newStringValueParser' ]; |
|
| 107 | - $callbacks['multilingualtext'] = [ $this, 'newMultilingualTextValueParser' ]; |
|
| 106 | + $callbacks['string'] = [$this, 'newStringValueParser']; |
|
| 107 | + $callbacks['multilingualtext'] = [$this, 'newMultilingualTextValueParser']; |
|
| 108 | 108 | $callbacks['wikibase-entityid'] = $callbacks['monolingualtext']; |
| 109 | 109 | |
| 110 | - $this->valueParserFactory = new ValueParserFactory( $callbacks ); |
|
| 110 | + $this->valueParserFactory = new ValueParserFactory($callbacks); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | return $this->valueParserFactory; |
@@ -45,12 +45,12 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @throws InvalidArgumentException |
| 47 | 47 | */ |
| 48 | - public function __construct( DataValue $localValue, array $externalValues, $status ) { |
|
| 49 | - Assert::parameterElementType( DataValue::class, $externalValues, '$externalValues' ); |
|
| 48 | + public function __construct(DataValue $localValue, array $externalValues, $status) { |
|
| 49 | + Assert::parameterElementType(DataValue::class, $externalValues, '$externalValues'); |
|
| 50 | 50 | |
| 51 | 51 | $this->localValue = $localValue; |
| 52 | 52 | $this->externalValues = $externalValues; |
| 53 | - $this->setStatus( $status ); |
|
| 53 | + $this->setStatus($status); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -79,14 +79,14 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @throws InvalidArgumentException |
| 81 | 81 | */ |
| 82 | - private function setStatus( $status ) { |
|
| 83 | - Assert::parameterType( 'string', $status, '$status' ); |
|
| 84 | - if ( !in_array( |
|
| 82 | + private function setStatus($status) { |
|
| 83 | + Assert::parameterType('string', $status, '$status'); |
|
| 84 | + if (!in_array( |
|
| 85 | 85 | $status, |
| 86 | - [ self::STATUS_MATCH, self::STATUS_PARTIAL_MATCH, self::STATUS_MISMATCH ] |
|
| 86 | + [self::STATUS_MATCH, self::STATUS_PARTIAL_MATCH, self::STATUS_MISMATCH] |
|
| 87 | 87 | ) |
| 88 | 88 | ) { |
| 89 | - throw new InvalidArgumentException( '$status must be one of the status constants.' ); |
|
| 89 | + throw new InvalidArgumentException('$status must be one of the status constants.'); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $this->status = $status; |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @throws InvalidArgumentException |
| 38 | 38 | */ |
| 39 | - public function __construct( $status, Reference $reference ) { |
|
| 39 | + public function __construct($status, Reference $reference) { |
|
| 40 | 40 | |
| 41 | 41 | $this->reference = $reference; |
| 42 | - $this->setStatus( $status ); |
|
| 42 | + $this->setStatus($status); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @throws InvalidArgumentException |
| 63 | 63 | */ |
| 64 | - private function setStatus( $status ) { |
|
| 65 | - Assert::parameterType( 'string', $status, '$status' ); |
|
| 66 | - if ( !in_array( |
|
| 64 | + private function setStatus($status) { |
|
| 65 | + Assert::parameterType('string', $status, '$status'); |
|
| 66 | + if (!in_array( |
|
| 67 | 67 | $status, |
| 68 | - [ self::STATUS_REFERENCES_MISSING, self::STATUS_REFERENCES_STATED ] |
|
| 68 | + [self::STATUS_REFERENCES_MISSING, self::STATUS_REFERENCES_STATED] |
|
| 69 | 69 | ) |
| 70 | 70 | ) { |
| 71 | - throw new InvalidArgumentException( '$status must be one of the status constants.' ); |
|
| 71 | + throw new InvalidArgumentException('$status must be one of the status constants.'); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $this->status = $status; |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @throws InvalidArgumentException |
| 28 | 28 | */ |
| 29 | - public function __construct( array $results = [] ) { |
|
| 30 | - Assert::parameterElementType( CrossCheckResult::class, $results, '$results' ); |
|
| 29 | + public function __construct(array $results = []) { |
|
| 30 | + Assert::parameterElementType(CrossCheckResult::class, $results, '$results'); |
|
| 31 | 31 | |
| 32 | 32 | $this->results = $results; |
| 33 | 33 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @param CrossCheckResult $result |
| 39 | 39 | */ |
| 40 | - public function add( CrossCheckResult $result ) { |
|
| 40 | + public function add(CrossCheckResult $result) { |
|
| 41 | 41 | $this->results[] = $result; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @param self $resultList |
| 48 | 48 | */ |
| 49 | - public function merge( self $resultList ) { |
|
| 50 | - $this->results = array_merge( $this->results, $resultList->results ); |
|
| 49 | + public function merge(self $resultList) { |
|
| 50 | + $this->results = array_merge($this->results, $resultList->results); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | public function getPropertyIds() { |
| 59 | 59 | $propertyIds = []; |
| 60 | 60 | |
| 61 | - foreach ( $this->results as $result ) { |
|
| 61 | + foreach ($this->results as $result) { |
|
| 62 | 62 | $propertyId = $result->getPropertyId(); |
| 63 | - if ( !in_array( $propertyId, $propertyIds ) ) { |
|
| 63 | + if (!in_array($propertyId, $propertyIds)) { |
|
| 64 | 64 | $propertyIds[] = $propertyId; |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -75,16 +75,16 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return self |
| 77 | 77 | */ |
| 78 | - public function getByPropertyId( PropertyId $propertyId ) { |
|
| 78 | + public function getByPropertyId(PropertyId $propertyId) { |
|
| 79 | 79 | $results = []; |
| 80 | 80 | |
| 81 | - foreach ( $this->results as $result ) { |
|
| 82 | - if ( $result->getPropertyId()->equals( $propertyId ) ) { |
|
| 81 | + foreach ($this->results as $result) { |
|
| 82 | + if ($result->getPropertyId()->equals($propertyId)) { |
|
| 83 | 83 | $results[] = $result; |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - return new self( $results ); |
|
| 87 | + return new self($results); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @codeCoverageIgnore |
| 104 | 104 | */ |
| 105 | 105 | public function getIterator() { |
| 106 | - return new ArrayIterator( $this->results ); |
|
| 106 | + return new ArrayIterator($this->results); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * @return int |
| 113 | 113 | */ |
| 114 | 114 | public function count() { |
| 115 | - return count( $this->results ); |
|
| 115 | + return count($this->results); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | } |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * @param DataValueComparer[] $dataValueComparers |
| 22 | 22 | */ |
| 23 | - public function __construct( array $dataValueComparers = [] ) { |
|
| 24 | - $this->assertAreDataValueComparer( $dataValueComparers ); |
|
| 23 | + public function __construct(array $dataValueComparers = []) { |
|
| 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 | |
@@ -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 | - [ $this, 'cleanDataString' ], |
|
| 120 | + [$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 | } |