FlagParenthesizedList::without()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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