Passed
Push — dev ( 8976f1...f79383 )
by Greg
07:34
created

Functions::getSubRecord()   B

Complexity

Conditions 7
Paths 11

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 20
nc 11
nop 4
dl 0
loc 30
rs 8.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2021 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\Functions;
21
22
/**
23
 * Class Functions - common functions
24
 */
25
class Functions
26
{
27
28
    /**
29
     * get CONT lines
30
     *
31
     * get the N+1 CONT or CONC lines of a gedcom subrecord
32
     *
33
     * @param int    $nlevel the level of the CONT lines to get
34
     * @param string $nrec   the gedcom subrecord to search in
35
     *
36
     * @return string a string with all CONT lines merged
37
     */
38
    public static function getCont(int $nlevel, string $nrec): string
39
    {
40
        $text = '';
41
42
        $subrecords = explode("\n", $nrec);
43
        foreach ($subrecords as $thisSubrecord) {
44
            if (substr($thisSubrecord, 0, 2) !== $nlevel . ' ') {
45
                continue;
46
            }
47
            $subrecordType = substr($thisSubrecord, 2, 4);
48
            if ($subrecordType === 'CONT') {
49
                $text .= "\n" . substr($thisSubrecord, 7);
50
            }
51
        }
52
53
        return $text;
54
    }
55
}
56