FlagParenthesizedList   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 52
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A with() 0 6 1
A without() 0 6 1
A __toString() 0 11 2
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