forked from theiconic/name-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and improvements; fix tests; add docblocks;
- Loading branch information
Showing
19 changed files
with
666 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace TheIconic\NameParser\Mapper; | ||
|
||
use TheIconic\NameParser\Part\AbstractPart; | ||
use TheIconic\NameParser\Part\Firstname; | ||
use TheIconic\NameParser\Part\Lastname; | ||
use TheIconic\NameParser\Part\Middlename; | ||
|
||
class MiddlenameMapper extends AbstractMapper | ||
{ | ||
|
||
/** | ||
* map middlenames in the parts array | ||
* | ||
* @param array $parts the name parts | ||
* @return array the mapped parts | ||
*/ | ||
public function map(array $parts) { | ||
if (count($parts) < 3) { | ||
return $parts; | ||
} | ||
|
||
// skip to after salutation | ||
$length = count($parts); | ||
$start = 0; | ||
for ($i = 0; $i < $length; $i++) { | ||
if ($parts[$i] instanceof Firstname) { | ||
$start = $i + 1; | ||
} | ||
} | ||
|
||
for ($k = $start; $k < $length; $k++) { | ||
$part = $parts[$k]; | ||
|
||
if ($part instanceof Lastname) { | ||
break; | ||
} | ||
|
||
if ($part instanceof AbstractPart) { | ||
continue; | ||
} | ||
|
||
$parts[$k] = new Middlename($part); | ||
} | ||
|
||
return $parts; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace TheIconic\NameParser\Mapper; | ||
|
||
use TheIconic\NameParser\Part\AbstractPart; | ||
use TheIconic\NameParser\Part\Nickname; | ||
|
||
// single letter, possibly followed by a period | ||
class NicknameMapper extends AbstractMapper | ||
{ | ||
|
||
/** | ||
* map nicknames in the parts array | ||
* | ||
* @param array $parts the name parts | ||
* @return array the mapped parts | ||
*/ | ||
function map(array $parts) { | ||
foreach ($parts as $k => $part) { | ||
if ($part instanceof AbstractPart) { | ||
continue; | ||
} | ||
|
||
if (preg_match('/^[\(\[\<\{].*[\)\]\>\}]$/', $part)) { | ||
$parts[$k] = new Nickname(substr($part, 1, -1)); | ||
} | ||
} | ||
|
||
return $parts; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.