Completed
Pull Request — master (#42)
by Frederik
01:52
created

ParenthesizedList   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
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 55
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
/**
7
 * Class ParenthesizedList
8
 * @package Genkgo\Mail\Protocol\Imap
9
 */
10
final class ParenthesizedList
11
{
12
13
    /**
14
     * @var array
15
     */
16
    private $list = [];
17
18
    /**
19
     * ParenthesizedList constructor.
20
     * @param array $list
21
     */
22 5
    public function __construct(array $list = [])
23
    {
24 5
        $this->list = $list;
25 5
    }
26
27
    /**
28
     * @param string $name
29
     * @return ParenthesizedList
30
     */
31 4
    public function with(string $name): self
32
    {
33 4
        $clone = clone $this;
34 4
        $clone->list[$name] = $name;
35 4
        return $clone;
36
    }
37
38
    /**
39
     * @param string $name
40
     * @return ParenthesizedList
41
     */
42 2
    public function without(string $name): self
43
    {
44 2
        $clone = clone $this;
45 2
        unset($clone->list[$name]);
46 2
        return $clone;
47
    }
48
49
    /**
50
     * @return string
51
     */
52 4
    public function __toString(): string
53
    {
54 4
        if (empty($this->list)) {
55 2
            return '';
56
        }
57
58 3
        return sprintf(
59 3
            '(%s)',
60 3
            implode(' ', $this->list)
61
        );
62
    }
63
64
}