Skip to content

Commit

Permalink
Merge pull request #19 from 365Werk/analysis-J2y7bW
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
HergenD authored Apr 22, 2021
2 parents 0a4e9b6 + 6133d2a commit ba36605
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Mrz/MrzParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private function getFirstLastName(string $fullName): array
private function getFullCountryName($countryCode)
{
$countryCode = preg_replace('/</', '', $countryCode);

return $this->countries[$countryCode] ?? null;
}
}
19 changes: 10 additions & 9 deletions src/Viz/VizParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public function match($parsed, $mrz, $text)
$firstNameScore = [];
foreach ($words as $wordKey => $word) {
$lastName = $word;
if(substr_count($parsed['last_name'], "<")){
$fillerAmount = range(0, substr_count($parsed['last_name'], "<"));
if (substr_count($parsed['last_name'], '<')) {
$fillerAmount = range(0, substr_count($parsed['last_name'], '<'));
$lastName = [];
foreach($fillerAmount as $count){
if(isset($words[$wordKey + $count])){
foreach ($fillerAmount as $count) {
if (isset($words[$wordKey + $count])) {
array_push($lastName, $words[$wordKey + $count]);
}
}
Expand All @@ -38,36 +38,37 @@ public function match($parsed, $mrz, $text)
$this->viz['last_name']['value'] = preg_replace('/</', ' ', $lastName);
$lastNameScore = $this->compare($parsed['last_name'], $lastName);
$this->viz['last_name']['confidence'] = $lastNameScore;

}
foreach ($parsed['first_name'] as $key => $first_name) {
if(!isset($firstNameScore[$key])){
if (! isset($firstNameScore[$key])) {
$firstNameScore[$key] = 0.4;
}
if ($this->compare($parsed['first_name'][$key], $word) > $firstNameScore[$key]) {
$firstNameScore[$key] = $this->compare($parsed['first_name'][$key], $word);
$first_name = [
'value' => $word,
'confidence' => $firstNameScore[$key]
'confidence' => $firstNameScore[$key],
];
$this->viz['first_name'][$key] = $first_name;
}
}
}
ksort($this->viz['first_name']);
$this->viz['first_name'] = array_values($this->viz['first_name']);

return $this->viz;
}

private function compare($mrz, $viz)
{
if(strlen($viz) == 0){
if (strlen($viz) == 0) {
return 0;
}
$viz = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $viz);
$viz = preg_replace('/([ ]|[-])/', '<', $viz);
$viz = preg_replace("/\p{P}/u", '', $viz);
$distance = levenshtein(strtolower($mrz), strtolower($viz));
return (strlen($viz)-$distance)/strlen($viz);

return (strlen($viz) - $distance) / strlen($viz);
}
}

0 comments on commit ba36605

Please sign in to comment.