FullNameHelper::explodeName()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 9.4285
nc 3
cc 3
eloc 14
nop 0
crap 3
1
<?php
2
namespace phrlog\FormHelper;
3
4
/**
5
 * Class FullNameHelper
6
 * @package FormHelper
7
 */
8
class FullNameHelper extends AbstractFormHelper
9
{
10
    use ValidationTrait;
11
12
    private $full_name;
13
    private $first;
14
    private $second;
15
    private $middle;
16
17
    /**
18
     * @param $full_name
19
     * @return $this
20
     */
21 6
    public function set($full_name)
22
    {
23 6
        $this->full_name = $full_name;
24 6
        return $this;
25
    }
26
27
    /**
28
     * @return $this
29
     */
30 2
    public function isCyrillic()
31
    {
32 2
        if (!ValidationTrait::isCyrillic($this->full_name)) {
33 1
            $this->full_name = false;
34
        }
35 2
        return $this;
36
    }
37
38
    /**
39
     * @return $this
40
     */
41 2
    public function isLatin()
42
    {
43 2
        if (!ValidationTrait::isLatin($this->full_name)) {
44 1
            $this->full_name = false;
45
        }
46 2
        return $this;
47
    }
48
49
    /**
50
     * @return $this
51
     */
52 2
    public function isText()
53
    {
54 2
        if (!ValidationTrait::isText($this->full_name)) {
55 1
            $this->full_name = false;
56
        }
57 2
        return $this;
58
    }
59
60
    /**
61
     * @return $this
62
     */
63 6
    public function explodeName()
64
    {
65 6
        $name = explode(' ', $this->full_name);
66 6
        $count_name = count($name);
67
68 6
        if ($count_name == 3) {
69 2
            $this->first = $name[0];
70 2
            $this->second = $name[1];
71 2
            $this->middle = $name[2];
72 4
        } elseif ($count_name == 2) {
73 1
            $this->first = $name[0];
74 1
            $this->second = $name[1];
75 1
            $this->middle = false;
76
        } else {
77 3
            $this->first = $this->second = $this->middle = false;
78
        }
79
80 6
        return $this;
81
    }
82
83
    /**
84
     * @return string
85
     */
86 6
    public function getFirstName()
87
    {
88 6
        return $this->first;
89
    }
90
91
    /**
92
     * @return string
93
     */
94 3
    public function getSecondName()
95
    {
96 3
        return $this->second;
97
    }
98
99
    /**
100
     * @return string
101
     */
102 3
    public function getMiddleName()
103
    {
104 3
        return $this->middle;
105
    }
106
107
    /**
108
     * @return array
109
     */
110 2
    public function get()
111
    {
112 2
        return ['first' => $this->first, 'second' => $this->second, 'middle' => $this->middle];
113
    }
114
}