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

SequenceSet   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 8 2
A single() 0 6 1
A sequence() 0 6 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 int
15
     */
16
    private $first;
17
    /**
18
     * @var int
19
     */
20
    private $last;
21
22
    /**
23
     * SequenceSet constructor.
24
     * @param int $first
25
     */
26
    public function __construct(int $first)
27
    {
28
        $this->first = $first;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function __toString(): string
35
    {
36
        return sprintf(
37
            '%s:%s',
38
            $this->first,
39
            $this->last ? $this->last : '*'
40
        );
41
    }
42
43
    /**
44
     * @param int $number
45
     * @return SequenceSet
46
     */
47
    public static function single(int $number): self
48
    {
49
        $set = new self($number);
50
        $set->last = $number;
51
        return $set;
52
    }
53
54
    /**
55
     * @param int $first
56
     * @param int $last
57
     * @return SequenceSet
58
     */
59
    public static function sequence(int $first, int $last): self
60
    {
61
        $set = new self($first);
62
        $set->last = $last;
63
        return $set;
64
    }
65
}