Completed
Pull Request — master (#42)
by Frederik
02:56
created

Item::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Imap\MessageData;
5
6
final class Item
7
{
8
    /**
9
     * @var string
10
     */
11
    private $name;
12
    /**
13
     * @var SectionList $sectionList
14
     */
15
    private $sections;
16
    /**
17
     * @var Partial
18
     */
19
    private $partial;
20
21
    /**
22
     * NameItem constructor.
23
     * @param string $name
24
     */
25
    public function __construct(string $name)
26
    {
27
        $this->name = $name;
28
    }
29
30
    /**
31
     * @param SectionList $sectionList
32
     * @return Item
33
     */
34
    public function withSections(SectionList $sectionList)
35
    {
36
        $clone = clone $this;
37
        $clone->sections = $sectionList;
38
        return $clone;
39
    }
40
41
    /**
42
     * @param Partial $partial
43
     * @return Item
44
     */
45
    public function withPartial(Partial $partial): self
46
    {
47
        $clone = clone $this;
48
        $clone->partial = $partial;
49
        return $clone;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getName(): string
56
    {
57
        return $this->name;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function __toString(): string
64
    {
65
        return sprintf(
66
            '%s%s%s',
67
            $this->name,
68
            $this->sections ? (string)$this->sections : '',
69
            $this->partial ? (string)$this->partial : ''
70
        );
71
    }
72
}