GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Name::__toString()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 2
b 0
f 0
nc 4
nop 0
dl 0
loc 13
rs 10
1
<?php
2
/**
3
 * This file is part of the O2System Reactor package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Reactor\DataStructures\Commons;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Spl\Patterns\Structural\Repository\AbstractRepository;
19
20
/**
21
 * Class Name
22
 *
23
 * @package O2System\Reactor\DataStructures\Commons
24
 */
25
class Name extends AbstractRepository
26
{
27
    /**
28
     * Name::__construct
29
     *
30
     * @param string|array $name
31
     */
32
    public function __construct($name)
33
    {
34
        if (is_string($name)) {
35
            $parts = explode(' ', trim($name));
36
            $name = [];
37
38
            if (count($parts) == 1) {
39
                $name[ 'first' ] = $parts[ 0 ];
40
                $name[ 'middle' ] = null;
41
                $name[ 'last' ] = null;
42
            } elseif (count($parts) == 2) {
43
                $name[ 'first' ] = $parts[ 0 ];
44
                $name[ 'middle' ] = null;
45
                $name[ 'last' ] = $parts[ 1 ];
46
            } elseif (count($parts) == 3) {
47
                $name[ 'first' ] = $parts[ 0 ];
48
                $name[ 'middle' ] = $parts[ 1 ];
49
                $name[ 'last' ] = $parts[ 2 ];
50
            } else {
51
                $name[ 'first' ] = $parts[ 0 ];
52
                $name[ 'middle' ] = $parts[ 1 ];
53
54
                $parts = array_slice($parts, 2);
55
                $name[ 'last' ] = implode(' ', $parts);
56
            }
57
        }
58
59
        foreach ($name as $key => $value) {
60
            $this->store($key, $value);
61
        }
62
    }
63
64
    // ------------------------------------------------------------------------
65
66
    /**
67
     * Name::__toString
68
     *
69
     * @return string
70
     */
71
    public function __toString()
72
    {
73
        $name = $this->offsetGet('first');
74
75
        if ($this->offsetExists('middle')) {
76
            $name .= ' ' . $this->offsetGet('middle');
77
        }
78
79
        if ($this->offsetExists('last')) {
80
            $name .= ' ' . $this->offsetGet('last');
81
        }
82
83
        return (string)trim($name);
84
    }
85
}