/** * Format the given name segment/part. * * @param string $part The part. * * @return S */ protected function format($part) { $part = S::create($part); switch ($part->substr(0, 2)) { case 'Pr': return $part->replace('Prefix', $this->tryGetLongVersion($this->name->getPrefix())); case 'Fi': return $part->replace('First', $this->tryGetLongVersion($this->name->getFirst())); case 'Mi': return $part->replace('Middle', $this->tryGetLongVersion($this->name->getMiddle())); case 'La': return $part->replace('Last', $this->tryGetLongVersion($this->name->getLast())); case 'P.': return $part->replace('P.', $this->tryGetShortVersion($this->name->getPrefix())); case 'F.': return $part->replace('F.', $this->tryGetShortVersion($this->name->getFirst())); case 'M.': return $part->replace('M.', $this->tryGetShortVersion($this->name->getMiddle())); case 'L.': return $part->replace('L.', $this->tryGetShortVersion($this->name->getLast())); default: return $part; } }
/** * Try and extract the prefix for this name. * * @param Simple $name The name to process. * @param array &$segments The given segments. * * @return void */ protected static function tryExtractPrefix($name, &$segments) { if (stripos($segments[0], '.') !== false) { // Prefix. $name->prefix(new Part($segments[0])); array_shift($segments); } }
public function testPrefixFirstMiddleAndLastNameFormatWithOddSpacingAndUnicode() { $string = 'Dr. Hubert Alfred Cumberdale'; $name = Simple::fromString($string); $fmt = new Format($name); $expected = '☂ Dr. Hubert Alfred Cumberdale'; $this->assertEquals($expected, $fmt->like('☂ Prefix First Middle Last ')); $expected = '☂ Dr. H. A. C.'; $this->assertEquals($expected, $fmt->like('☂ P. F. M. L.')); $expected = '☂ Dr. Hubert A. C.'; $this->assertEquals($expected, $fmt->like('☂ Prefix First M. L.')); $expected = '☂ Dr. Cumberdale, H. A.'; $this->assertEquals($expected, $fmt->like('☂ Prefix Last, F. M.')); }
/** * @expectedException \Enzyme\Name\NameException */ public function testSimpleNameThrowsExceptionOnIncorrectStringData() { $name = Simple::fromString(''); }