Completed
Pull Request — master (#42)
by Frederik
04:41
created

DateCriterion::on()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
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\Request\SearchCriteria;
5
6
/**
7
 * Class FlagCriterium
8
 * @package Genkgo\Mail\Protocol\Imap\Request\SearchCriteria
9
 */
10
final class DateCriterion implements CriterionInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    private $name;
16
    /**
17
     * @var \DateTimeImmutable
18
     */
19
    private $moment;
20
21
    /**
22
     * FlagCriterium constructor.
23
     * @param string $name
24
     * @param \DateTimeImmutable $moment
25
     */
26 8
    private function __construct(string $name, \DateTimeImmutable $moment)
27
    {
28 8
        $this->name = $name;
29 8
        $this->moment = $moment;
30 8
    }
31
32
    /**
33
     * @return string
34
     */
35 8
    public function __toString(): string
36
    {
37 8
        return sprintf(
38 8
            '%s %s',
39 8
            $this->name,
40 8
            $this->moment->format('j-D-Y')
41
        );
42
    }
43
44
    /**
45
     * @param \DateTimeImmutable $moment
46
     * @return DateCriterion
47
     */
48 2
    public static function before(\DateTimeImmutable $moment): self
49
    {
50 2
        return new self('BEFORE', $moment);
51
    }
52
53
    /**
54
     * @param \DateTimeImmutable $moment
55
     * @return DateCriterion
56
     */
57 1
    public static function after(\DateTimeImmutable $moment): self
58
    {
59 1
        return new self('AFTER', $moment);
60
    }
61
62
    /**
63
     * @param \DateTimeImmutable $moment
64
     * @return DateCriterion
65
     */
66 1
    public static function on(\DateTimeImmutable $moment): self
67
    {
68 1
        return new self('ON', $moment);
69
    }
70
71
    /**
72
     * @param \DateTimeImmutable $moment
73
     * @return DateCriterion
74
     */
75 1
    public static function since(\DateTimeImmutable $moment): self
76
    {
77 1
        return new self('SINCE', $moment);
78
    }
79
80
    /**
81
     * @param \DateTimeImmutable $moment
82
     * @return DateCriterion
83
     */
84 1
    public static function sentBefore(\DateTimeImmutable $moment): self
85
    {
86 1
        return new self('SENTBEFORE', $moment);
87
    }
88
89
    /**
90
     * @param \DateTimeImmutable $moment
91
     * @return DateCriterion
92
     */
93 1
    public static function sentAfter(\DateTimeImmutable $moment): self
94
    {
95 1
        return new self('SENTAFTER', $moment);
96
    }
97
98
    /**
99
     * @param \DateTimeImmutable $moment
100
     * @return DateCriterion
101
     */
102
    public static function sentOn(\DateTimeImmutable $moment): self
103
    {
104
        return new self('SENTON', $moment);
105
    }
106
107
    /**
108
     * @param \DateTimeImmutable $moment
109
     * @return DateCriterion
110
     */
111 1
    public static function sentSince(\DateTimeImmutable $moment): self
112
    {
113 1
        return new self('SENTSINCE', $moment);
114
    }
115
}