Completed
Pull Request — master (#42)
by Frederik
03:52
created

ParenthesizedList::with()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Imap;
5
6
/**
7
 * Class ParenthesizedList
8
 * @package Genkgo\Mail\Protocol\Imap
9
 */
10
final class ParenthesizedList
11
{
12
13
    /**
14
     * @var array
15
     */
16
    private $list = [];
17
18
    /**
19
     * ParenthesizedList constructor.
20
     * @param array $list
21
     */
22
    public function __construct(array $list = [])
23
    {
24
        $this->list = $list;
25
    }
26
27
    /**
28
     * @param string $name
29
     * @return ParenthesizedList
30
     */
31
    public function with(string $name): self
32
    {
33
        $clone = clone $this;
34
        $clone->list[] = $name;
35
        return $clone;
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function __toString(): string
42
    {
43
        if (empty($this->list)) {
44
            return '';
45
        }
46
47
        return sprintf(
48
            '(%s)',
49
            implode(' ', $this->list)
50
        );
51
    }
52
53
}