Completed
Pull Request — master (#42)
by Frederik
02:22
created

FlagParenthesizedList::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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 2
    public function __construct(array $list = [])
23
    {
24 2
        $this->flags = $list;
25 2
    }
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[] = $flag;
35
        return $clone;
36
    }
37
38
    /**
39
     * @return string
40
     */
41 1
    public function __toString(): string
42
    {
43 1
        if (empty($this->flags)) {
44
            return '';
45
        }
46
47 1
        return sprintf(
48 1
            '(%s)',
49 1
            implode(' ', $this->flags)
50
        );
51
    }
52
53
}