Skip to content

Commit

Permalink
Merge pull request #14 from theiconic/feature/allow-salutation-at-end
Browse files Browse the repository at this point in the history
Allow having salutations in last position without comma-separation (fixes #11)
  • Loading branch information
wyrfel committed Aug 28, 2018
2 parents 81de7cb + f7f4888 commit 17ce0ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Mapper/FirstnameMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ protected function getStartIndex(array $parts): int
return 0;
}

if ($index === count($parts) - 1) {
return 0;
}

return $index + 1;
}
}
7 changes: 2 additions & 5 deletions src/Mapper/LastnameMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use TheIconic\NameParser\Part\Lastname;
use TheIconic\NameParser\Part\LastnamePrefix;
use TheIconic\NameParser\Part\Nickname;
use TheIconic\NameParser\Part\Salutation;
use TheIconic\NameParser\Part\Suffix;

class LastnameMapper extends AbstractMapper
Expand Down Expand Up @@ -49,11 +50,7 @@ protected function mapReversedParts(array $parts): array
$length = count($parts);

foreach ($parts as $k => $part) {
if ($part instanceof Suffix) {
continue;
}

if ($part instanceof Nickname) {
if ($part instanceof Suffix || $part instanceof Nickname || $part instanceof Salutation) {
continue;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@ public function provider()
'middlename' => 'Eric',
]
],
[
'PAUL M LEWIS MR',
[
'salutation' => 'Mr.',
'firstname' => 'Paul',
'initials' => 'M',
'lastname' => 'Lewis',
]
]
];
}

Expand Down

0 comments on commit 17ce0ba

Please sign in to comment.