Completed
Pull Request — master (#22)
by
unknown
01:13
created

FullgivennameMapper::map()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.0777
c 0
b 0
f 0
cc 6
nc 6
nop 1
1
<?php
2
3
namespace TheIconic\NameParser\Mapper;
4
5
use TheIconic\NameParser\Part\AbstractPart;
6
use TheIconic\NameParser\Part\Firstname;
7
use TheIconic\NameParser\Part\Lastname;
8
use TheIconic\NameParser\Part\Middlename;
9
use TheIconic\NameParser\Part\Fullgivenname;
10
11
class FullgivennameMapper extends AbstractMapper
12
{
13
14
    /**
15
     * map middlenames in the parts array
16
     *
17
     * @param array $parts the name parts
18
     * @return array the mapped parts
19
     */
20
    public function map(array $parts): array
21
    {
22
        $givenNameParts = [];
23
        foreach ($parts as $part) {
24
            if (
25
                ($part instanceof \TheIconic\NameParser\Part\Firstname)
26
                || ($part instanceof \TheIconic\NameParser\Part\Middlename)
27
                || ($part instanceof \TheIconic\NameParser\Part\Initial)
28
            ) {
29
                $givenNameParts[] = $part->normalize();
30
            }
31
        }
32
        if (count($givenNameParts) > 0) {
33
            $parts[] = new Fullgivenname(implode(' ', $givenNameParts));
34
        }
35
        return $parts;
36
    }
37
}
38