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.
Completed
Pull Request — master (#58)
by joseph
18:31
created

FullNameEmbeddable::getFormatted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 7
cts 7
cp 1
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Identity;
4
5
use Doctrine\ORM\Mapping\ClassMetadata;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Identity\FullNameEmbeddableInterface;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\AbstractEmbeddableObject;
8
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
9
10
class FullNameEmbeddable extends AbstractEmbeddableObject implements FullNameEmbeddableInterface
11
{
12
    /**
13
     * The title or Honorific Prefix, for example Mr, Dr
14
     *
15
     * @var string
16
     */
17
    private $title;
18
19
    /**
20
     * The first or given name
21
     *
22
     * @var string
23
     */
24
    private $firstName;
25
26
    /**
27
     * An array of middle names
28
     *
29
     * @var array
30
     */
31
    private $middleNames;
32
33
    /**
34
     * The last or surname
35
     *
36
     * @var string
37
     */
38
    private $lastName;
39
40
    /**
41
     * The honorific suffix, for example Jr
42
     *
43
     * @var string
44
     */
45
    private $suffix;
46
47
    /**
48
     * @return string
49
     */
50 1
    public function getTitle(): string
51
    {
52 1
        return $this->title;
53
    }
54
55
    /**
56
     * @param string $title
57
     *
58
     * @return FullNameEmbeddableInterface
59
     */
60 2
    public function setTitle(string $title): FullNameEmbeddableInterface
61
    {
62 2
        $this->title = $title;
63
64 2
        return $this;
65
    }
66
67
    /**
68
     * @return string
69
     */
70 1
    public function getFirstName(): string
71
    {
72 1
        return $this->firstName;
73
    }
74
75
    /**
76
     * @param string $firstName
77
     *
78
     * @return FullNameEmbeddableInterface
79
     */
80 2
    public function setFirstName(string $firstName): FullNameEmbeddableInterface
81
    {
82 2
        $this->firstName = $firstName;
83
84 2
        return $this;
85
    }
86
87
    /**
88
     * @return array
89
     */
90 1
    public function getMiddleNames(): array
91
    {
92 1
        return $this->middleNames;
93
    }
94
95
    /**
96
     * @param array $middleNames
97
     *
98
     * @return FullNameEmbeddableInterface
99
     */
100 2
    public function setMiddleNames(array $middleNames): FullNameEmbeddableInterface
101
    {
102 2
        $this->middleNames = $middleNames;
103
104 2
        return $this;
105
    }
106
107
    /**
108
     * @return string
109
     */
110 1
    public function getLastName(): string
111
    {
112 1
        return $this->lastName;
113
    }
114
115
    /**
116
     * @param string $lastName
117
     *
118
     * @return FullNameEmbeddableInterface
119
     */
120 2
    public function setLastName(string $lastName): FullNameEmbeddableInterface
121
    {
122 2
        $this->lastName = $lastName;
123
124 2
        return $this;
125
    }
126
127
    /**
128
     * @return string
129
     */
130 1
    public function getSuffix(): string
131
    {
132 1
        return $this->suffix;
133
    }
134
135
    /**
136
     * @param string $suffix
137
     *
138
     * @return FullNameEmbeddableInterface
139
     */
140 2
    public function setSuffix(string $suffix): FullNameEmbeddableInterface
141
    {
142 2
        $this->suffix = $suffix;
143
144 2
        return $this;
145
    }
146
147
    /**
148
     * Get the full name as a single string
149
     *
150
     * @return string
151
     */
152 1
    public function getFormatted(): string
153
    {
154 1
        return $this->format(
155
            [
156 1
                $this->title,
157 1
                $this->firstName,
158 1
                $this->format($this->middleNames),
159 1
                $this->lastName,
160 1
                $this->suffix,
161
            ]
162
        );
163
    }
164
165
    /**
166
     * Convert the array into a single space separated list
167
     *
168
     * @param array $items
169
     *
170
     * @return string
171
     */
172
    private function format(array $items): string
173
    {
174
        return trim(
175
            implode(
176
                ' ',
177
                array_map(
178
                    'trim',
179
                    array_filter(
180
                        $items
181
                    )
182
                )
183
            )
184
        );
185
    }
186
187
    /**
188
     * @param ClassMetadata $metadata
189
     * @SuppressWarnings(PHPMD.StaticAccess)
190
     */
191 1
    public static function loadMetadata(ClassMetadata $metadata): void
192
    {
193 1
        $builder = self::setEmbeddableAndGetBuilder($metadata);
194 1
        MappingHelper::setSimpleFields(
195
            [
196 1
                FullNameEmbeddableInterface::EMBEDDED_PROP_TITLE       => MappingHelper::TYPE_STRING,
197
                FullNameEmbeddableInterface::EMBEDDED_PROP_FIRSTNAME   => MappingHelper::TYPE_STRING,
198 1
                FullNameEmbeddableInterface::EMBEDDED_PROP_MIDDLENAMES => MappingHelper::TYPE_JSON,
199
                FullNameEmbeddableInterface::EMBEDDED_PROP_LASTNAME    => MappingHelper::TYPE_STRING,
200
                FullNameEmbeddableInterface::EMBEDDED_PROP_SUFFIX      => MappingHelper::TYPE_STRING,
201
            ],
202 1
            $builder
203
        );
204 1
    }
205
}
206