NameItem   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 37
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getName() 0 4 1
A __toString() 0 4 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
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