FullNameParser::is_line_suffix PHP Method

is_line_suffix() protected method

Checks word against array of common lineage suffixes
protected is_line_suffix ( string $word, string $name ) : mixed
$word string the single word you wish to test
$name string full name for context in determining edge-cases
return mixed boolean if false, string if true (returns suffix)
    protected function is_line_suffix($word, $name)
    {
        # Ignore periods and righ commas, normalize case
        $word = str_replace('.', '', strtolower($word));
        $word = rtrim($word, ',');
        # Search the array for our word
        $line_match = array_search($word, array_map('strtolower', $this->dict['suffixes']['line']));
        # Now test our edge cases based on lineage
        if ($line_match !== false) {
            # Store our match
            $matched_case = $this->dict['suffixes']['line'][$line_match];
            # Remove it from the array
            $temp_array = $this->dict['suffixes']['line'];
            unset($temp_array[$line_match]);
            # Make sure we're dealing with the suffix and not a surname
            if ($word == 'senior' || $word == 'junior') {
                # If name is Joshua Senior, it's pretty likely that Senior is the surname
                # However, if the name is Joshua Jones Senior, then it's likely a suffix
                if (str_word_count($name) < 3) {
                    return false;
                }
                # If the word Junior or Senior is contained, but so is some other
                # lineage suffix, then the word is likely a surname and not a suffix
                foreach ($temp_array as $suffix) {
                    if (preg_match("/\\b" . $suffix . "\\b/i", $name)) {
                        return false;
                    }
                }
            }
            return $matched_case;
        }
        return false;
    }