Completed
Push — master ( 09801d...b7f648 )
by Andre
01:52
created

InitialMapper::isInitial()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace TheIconic\NameParser\Mapper;
4
5
use TheIconic\NameParser\Part\AbstractPart;
6
use TheIconic\NameParser\Part\Initial;
7
8
/**
9
 * single letter, possibly followed by a period
10
 */
11
class InitialMapper extends AbstractMapper
12
{
13
    /**
14
     * map intials in parts array
15
     *
16
     * @param array $parts the name parts
17
     * @return array the mapped parts
18
     */
19 View Code Duplication
    public function map(array $parts)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21
        foreach ($parts as $k => $part) {
22
            if ($part instanceof AbstractPart) {
23
                continue;
24
            }
25
26
            if ($this->isInitial($part)) {
27
                $parts[$k] = new Initial($part);
28
            }
29
        }
30
31
        return $parts;
32
    }
33
34
    /**
35
     * @param string $part
36
     * @return bool
37
     */
38
    protected function isInitial(string $part): bool
39
    {
40
        $length = strlen($part);
41
42
        if (1 === $length) {
43
            return true;
44
        }
45
46
        return ($length === 2 && substr($part, -1) ===  '.');
47
    }
48
}
49