NameItem::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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
final class NameItem implements ItemInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    private $name;
14
    
15
    private const VALID_CHAR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.+-";
16
17
    /**
18
     * @param string $name
19
     */
20 38
    public function __construct(string $name)
21
    {
22 38
        if (\strlen($name) !== \strspn($name, self::VALID_CHAR)) {
23 1
            throw new \InvalidArgumentException('Name can only contain uppercase A-Z chars: ' . $name);
24
        }
25
26 37
        $this->name = $name;
27 37
    }
28
29
    /**
30
     * @return string
31
     */
32 35
    public function getName(): string
33
    {
34 35
        return $this->name;
35
    }
36
37
    /**
38
     * @return string
39
     */
40 10
    public function __toString(): string
41
    {
42 10
        return $this->name;
43
    }
44
}
45