Completed
Pull Request — master (#42)
by Frederik
06:33
created

FlagParenthesizedList::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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