Completed
Pull Request — master (#42)
by Frederik
04:15 queued 01:07
created

NameItem::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Imap\MessageData\Item;
5
6
use Genkgo\Mail\Protocol\Imap\MessageData\ItemInterface;
7
8
/**
9
 * Class NameItem
10
 * @package Genkgo\Mail\Protocol\Imap\MessageData\GenericItem
11
 */
12
final class NameItem implements ItemInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    private $name;
18
19
    /**
20
     *
21
     */
22
    private CONST VALID_CHAR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.+-";
23
24
    /**
25
     * NameItem constructor.
26
     * @param string $name
27
     */
28 26
    public function __construct(string $name)
29
    {
30 26
        if (strlen($name) !== strspn($name, self::VALID_CHAR)) {
31 1
            throw new \InvalidArgumentException('name can only contain uppercase A-Z chars');
32
        }
33
34 25
        $this->name = $name;
35 25
    }
36
37
    /**
38
     * @return string
39
     */
40 22
    public function getName(): string
41
    {
42 22
        return $this->name;
43
    }
44
45
    /**
46
     * @return string
47
     */
48 7
    public function __toString(): string
49
    {
50 7
        return $this->name;
51
    }
52
}