Completed
Push — master ( e8b19e...87df92 )
by Andrew
02:42
created

Prefix   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 6
eloc 14
c 0
b 0
f 0
dl 0
loc 37
ccs 13
cts 15
cp 0.8667
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFemalePrefix() 0 3 1
A __construct() 0 4 1
A getPrefixByGender() 0 9 3
A getMalePrefix() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KRDigital\NamesDetector\Entry\Prefix;
6
7
use KRDigital\NamesDetector\Entry\Gender;
8
9
class Prefix implements PrefixInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $malePrefix;
15
16
    /**
17
     * @var string
18
     */
19
    protected $femalePrefix;
20
21 4
    public function __construct(string $malePrefix = null, string $femalePrefix = null)
22
    {
23 4
        $this->malePrefix = $malePrefix ?? 'Уважаемый';
24 4
        $this->femalePrefix = $femalePrefix ?? 'Уважаемая';
25 4
    }
26
27 2
    public function getMalePrefix(): string
28
    {
29 2
        return $this->malePrefix;
30
    }
31
32 3
    public function getFemalePrefix(): string
33
    {
34 3
        return $this->femalePrefix;
35
    }
36
37 1
    public function getPrefixByGender(Gender $gender): string
38
    {
39 1
        switch ($gender->getValue()) {
40 1
            case Gender::GENDER_MALE:
41
                return $this->getMalePrefix();
42 1
            case Gender::GENDER_FEMALE:
43 1
                return $this->getFemalePrefix();
44
            default:
45
                throw new \LogicException(\sprintf('Invalid type %s', $gender->getValue()));
46
        }
47
    }
48
}
49