FullNameParser::get_pro_suffix PHP Method

get_pro_suffix() public method

Checks for the existence of, and returns professional suffix
public get_pro_suffix ( string $name ) : mixed
$name string the name you wish to test
return mixed returns the suffix if exists, false otherwise
    public function get_pro_suffix($name)
    {
        $found_suffix_arr = array();
        foreach ($this->dict['suffixes']['prof'] as $suffix) {
            if (preg_match('/[,\\s]+' . preg_quote($suffix) . '\\b/i', $name, $matches)) {
                $found_suffix = trim($matches[0]);
                $found_suffix = rtrim($found_suffix, ',');
                $found_suffix = ltrim($found_suffix, ',');
                $found_suffix_arr[] = trim($found_suffix);
            }
        }
        return $found_suffix_arr;
    }

Usage Example

 /** @test */
 public function testProSuffix()
 {
     $parser = new FullNameParser();
     $tests = ['Smarty Pants Phd' => 'Phd', 'Smarty Pants PHD' => 'PHD', 'OLD MACDONALD, PHD' => 'PHD'];
     $tests_no_match = ['OLD MACDONALD', 'OLD PHDMACDONALDPHD', 'Prof. Ron Brown'];
     foreach ($tests as $test => $expected_result) {
         $suffixes = $parser->get_pro_suffix($test);
         // $this->assertTrue(false !== array_search($expected_result, $suffixes));
         $this->assertContains($expected_result, $suffixes);
     }
     foreach ($tests_no_match as $test) {
         $suffixes = $parser->get_pro_suffix($test);
         // Should get empty array
         $this->assertSame($suffixes, []);
     }
 }