Completed
Pull Request — master (#22)
by
unknown
02:30
created

FullgivennameMapper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A map() 0 17 6
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