Completed
Push — master ( 46f3eb...7c230f )
by Mathieu
02:46 queued 40s
created

OpenLog::setEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Charcoal\Email\Objects;
6
7
use DateTime;
8
use DateTimeInterface;
9
use Exception;
10
use InvalidArgumentException;
11
12
// From 'locomotivemtl/charcoal-core'
13
use Charcoal\Model\AbstractModel;
14
15
/**
16
 * Open log
17
 */
18
class OpenLog extends AbstractModel
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: hasProperty, p, properties, property
Loading history...
19
{
20
    /**
21
     * @var string|null
22
     */
23
    private $email;
24
25
    /**
26
     * @var DateTimeInterface|null
27
     */
28
    private $ts;
29
30
    /**
31
     * @var string|null
32
     */
33
    private $ip;
34
35
36
    /**
37
     * @param string|null $emailId The email (log) id.
38
     * @return self
39
     */
40
    public function setEmail(?string $emailId)
41
    {
42
        $this->email = $emailId;
43
        return $this;
44
    }
45
46
    /**
47
     * @return string|null
48
     */
49
    public function email(): ?string
50
    {
51
        return $this->email;
52
    }
53
54
    /**
55
     * @param  null|string|DateTimeInterface $ts The "timestamp" datetime value.
56
     * @throws InvalidArgumentException If the timestamp is not a valid datetime value.
57
     * @return self
58
     */
59
    public function setTs($ts)
60
    {
61
        if ($ts === null) {
62
            $this->ts = null;
63
            return $this;
64
        }
65
66
        if (is_string($ts)) {
67
            try {
68
                $ts = new DateTime($ts);
69
            } catch (Exception $e) {
70
                throw new InvalidArgumentException($e->getMessage());
71
            }
72
        }
73
74
        if (!($ts instanceof DateTimeInterface)) {
75
            throw new InvalidArgumentException(
76
                'Invalid "Send Date" value. Must be a date/time string or a DateTime object.'
77
            );
78
        }
79
80
        $this->ts = $ts;
81
        return $this;
82
    }
83
84
    /**
85
     * @return null|DateTimeInterface
86
     */
87
    public function ts()
88
    {
89
        return $this->ts;
90
    }
91
92
    /**
93
     * @param string|null $ip The IP address.
94
     * @return self
95
     */
96
    public function setIp(?string $ip)
97
    {
98
        $this->ip = $ip;
99
        return $this;
100
    }
101
102
    /**
103
     * @return string|null
104
     */
105
    public function ip(): ?string
106
    {
107
        return $this->ip;
108
    }
109
}
110