Passed
Push — main ( 4118eb...a5c812 )
by Greg
07:41
created

MatrilinealSurnameTradition::description()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2022 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\SurnameTradition;
21
22
use Fisharebest\Webtrees\Elements\NameType;
23
use Fisharebest\Webtrees\I18N;
24
use Fisharebest\Webtrees\Individual;
25
26
/**
27
 * Children take their mother’s surname.
28
 */
29
class MatrilinealSurnameTradition extends DefaultSurnameTradition
30
{
31
    /**
32
     * The name of this surname tradition
33
     *
34
     * @return string
35
     */
36
    public function name(): string
37
    {
38
        /* I18N: A system where children take their mother’s surname */
39
        return I18N::translate('matrilineal');
40
    }
41
42
    /**
43
     * A short description of this surname tradition
44
     *
45
     * @return string
46
     */
47
    public function description(): string
48
    {
49
        /* I18N: In the matrilineal surname tradition, ... */
50
        return I18N::translate('Children take their mother’s surname.');
51
    }
52
53
    /**
54
     * What name is given to a new child
55
     *
56
     * @param Individual|null $father
57
     * @param Individual|null $mother
58
     * @param string          $sex
59
     *
60
     * @return array<int,string>
61
     */
62
    public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array
63
    {
64
        if (preg_match(self::REGEX_SPFX_SURN, $this->extractName($mother), $match)) {
65
            $name = $match['NAME'];
66
            $spfx = $match['SPFX'];
67
            $surn = $match['SURN'];
68
69
            return [
70
                $this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SPFX' => $spfx, 'SURN' => $surn]),
71
            ];
72
        }
73
74
        return parent::newChildNames($father, $mother, $sex);
75
    }
76
77
    /**
78
     * What name is given to a new parent
79
     *
80
     * @param Individual $child
81
     * @param string                           $sex
82
     *
83
     * @return array<int,string>
84
     */
85
    public function newParentNames(Individual $child, string $sex): array
86
    {
87
        if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match)) {
88
            $name = $match['NAME'];
89
            $spfx = $match['SPFX'];
90
            $surn = $match['SURN'];
91
92
            return [
93
                $this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SPFX' => $spfx, 'SURN' => $surn]),
94
            ];
95
        }
96
97
        return parent::newParentNames($child, $sex);
98
    }
99
}
100