ParenthesizedList   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 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