ParenthesizedList::__toString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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