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

SequenceSet::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

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 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Imap\Request;
5
6
/**
7
 * Class SequenceSet
8
 * @package Genkgo\Mail\Protocol\Imap\Request
9
 */
10
final class SequenceSet
11
{
12
13
    /**
14
     * @var array
15
     */
16
    private $set = [];
17
18
    /**
19
     * SequenceSet constructor.
20
     */
21 14
    private function __construct()
22
    {
23
        // this constructor is protected in order to force
24
        // a set to have at least one item
25 14
    }
26
27
    /**
28
     * @param int $number
29
     * @return SequenceSet
30
     */
31 1
    public function withSingle(int $number): self
32
    {
33 1
        $set = clone $this;
34 1
        $set->set[] = $number;
35 1
        return $set;
36
    }
37
38
    /**
39
     * @param int $first
40
     * @param int $last
41
     * @return SequenceSet
42
     */
43 1
    public function withRange(int $first, int $last): self
44
    {
45 1
        $set = clone $this;
46 1
        $set->set[] = (string)$first.':'.(string)$last;
47 1
        return $set;
48
    }
49
50
    /**
51
     * @param int $first
52
     * @return SequenceSet
53
     */
54 1
    public function withInfiniteRange(int $first): self
55
    {
56 1
        $set = clone $this;
57 1
        $set->set[] = (string)$first.':*';
58 1
        return $set;
59
    }
60
61
    /**
62
     * @return string
63
     */
64 14
    public function __toString(): string
65
    {
66 14
        return implode(',', $this->set);
67
    }
68
69
    /**
70
     * @return SequenceSet
71
     */
72 1
    public static function all(): self
73
    {
74 1
        $set = new self();
75 1
        $set->set = ['*'];
76 1
        return $set;
77
    }
78
79
    /**
80
     * @param int $number
81
     * @return SequenceSet
82
     */
83 9
    public static function single(int $number): self
84
    {
85 9
        $set = new self();
86 9
        $set->set = [(string)$number];
87 9
        return $set;
88
    }
89
90
    /**
91
     * @param int $first
92
     * @param int $last
93
     * @return SequenceSet
94
     */
95 3
    public static function range(int $first, int $last): self
96
    {
97 3
        $set = new self();
98 3
        $set->set = [(string)$first.':'.(string)$last];
99 3
        return $set;
100
    }
101
102
    /**
103
     * @param int $first
104
     * @return SequenceSet
105
     */
106 1
    public static function infiniteRange(int $first): self
107
    {
108 1
        $set = new self();
109 1
        $set->set = [(string)$first.':*'];
110 1
        return $set;
111
    }
112
}