diff --git a/lib/Simresults/Driver.php b/lib/Simresults/Driver.php index 142e33c..9c4aa4c 100644 --- a/lib/Simresults/Driver.php +++ b/lib/Simresults/Driver.php @@ -70,6 +70,14 @@ public function getName($shorten_lastname=FALSE, $shorten_firstname=FALSE) $names = explode(' ', $name); if (count($names) > 1 AND $shorten_lastname) { $last_name = array_pop($names); + + // First character is not a letter, we will not threat this as + // lastname and will try to get another part when more lastname + // parts are available + if (!preg_match('/[a-z]/i', $last_name[0]) and count($names) > 1) { + $last_name = array_pop($names); + } + $name = $names[0]." ".$last_name[0]; } diff --git a/spec/Simresults/DriverSpec.php b/spec/Simresults/DriverSpec.php index 42ae2fd..925880f 100644 --- a/spec/Simresults/DriverSpec.php +++ b/spec/Simresults/DriverSpec.php @@ -92,6 +92,11 @@ function it_can_return_a_shorten_firstname_and_lastname() $this->setName('Aname with a space at the end '); $this->getName()->shouldReturn('Aname with a space at the end'); $this->getName(true, true)->shouldReturn('A. e'); + + // Ignore non letters as lastname + $this->setName('G Mossoni [FNX]'); + $this->getName()->shouldReturn('G Mossoni [FNX]'); + $this->getName(true, true)->shouldReturn('G. M'); } }