AbstractDate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A setDate() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace Ddeboer\Imap\Search\Date;
4
5
use DateTime;
6
use Ddeboer\Imap\Search\AbstractCondition;
7
8
/**
9
 * Represents a date condition.
10
 */
11
abstract class AbstractDate extends AbstractCondition
12
{
13
    /**
14
     * Format for dates to be sent to the IMAP server.
15
     *
16
     * @var string
17
     */
18
    const DATE_FORMAT = 'Y-m-d';
19
20
    /**
21
     * The date to be used for the condition.
22
     *
23
     * @var DateTime
24
     */
25
    protected $date;
26
27
    /**
28
     * Constructor.
29
     *
30
     * @param DateTime $date Optional date for the condition.
31
     */
32
    public function __construct(DateTime $date = null)
33
    {
34
        if ($date) {
35
            $this->setDate($date);
36
        }
37
    }
38
39
    /**
40
     * Sets the date for the condition.
41
     *
42
     * @param DateTime $date
43
     */
44
    public function setDate(DateTime $date)
45
    {
46
        $this->date = $date;
47
    }
48
49
    /**
50
     * Converts the condition to a string that can be sent to the IMAP server.
51
     *
52
     * @return string
53
     */
54
    public function __toString()
55
    {
56
        return $this->getKeyword() . ' "' . $this->date->format(self::DATE_FORMAT) .'"';
57
    }
58
}
59