. */ declare(strict_types=1); namespace Fisharebest\Webtrees\SurnameTradition; use Fisharebest\Webtrees\Elements\NameType; use Fisharebest\Webtrees\Individual; use function var_dump; /** * Children take their father’s surname. Wives take their husband’s surname. */ class PaternalSurnameTradition extends PatrilinealSurnameTradition { /** * What name is given to a new parent * * @param Individual $child * @param string $sex * * @return array */ public function newParentNames(Individual $child, string $sex): array { if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match)) { $name = $match['NAME']; $spfx = $match['SPFX']; $surn = $match['SURN']; return [ $this->buildName('//', ['TYPE' => NameType::TYPE_BIRTH]), $this->buildName($name, ['TYPE' => NameType::TYPE_MARRIED, 'SPFX' => $spfx, 'SURN' => $surn]), ]; } return parent::newParentNames($child, $sex); } /** * What names are given to a new spouse * * @param Individual $spouse * @param string $sex * * @return array */ public function newSpouseNames(Individual $spouse, string $sex): array { if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($spouse), $match)) { $name = $match['NAME']; $spfx = $match['SPFX']; $surn = $match['SURN']; return [ $this->buildName('//', ['TYPE' => NameType::TYPE_BIRTH]), $this->buildName($name, ['TYPE' => NameType::TYPE_MARRIED, 'SPFX' => $spfx, 'SURN' => $surn]), ]; } return parent::newSpouseNames($spouse, $sex); } }