Completed
Pull Request — master (#7)
by Hamoud
05:51
created

MobilyWsMessage   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 2
dl 0
loc 94
ccs 0
cts 38
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 4 1
A text() 0 6 1
A time() 0 16 3
A dateSend() 0 6 2
A timeSend() 0 6 2
1
<?php
2
3
namespace NotificationChannels\MobilyWs;
4
5
use Carbon\Carbon;
6
use DateTime;
7
use DateTimeInterface;
8
use NotificationChannels\MobilyWs\Exceptions\CouldNotSendNotification;
9
10
class MobilyWsMessage
11
{
12
    /** @var string */
13
    public $text;
14
15
    /** @var Carbon */
16
    public $time;
17
18
    /**
19
     * Create new instance of mobilyWsMessage.
20
     *
21
     * @param string $text
22
     *
23
     * @return static
24
     */
25
    public static function create($text = '')
26
    {
27
        return new static($text);
28
    }
29
30
    /**
31
     * MobilyWsMessage constructor.
32
     *
33
     * @param string $text
34
     */
35
    public function __construct($text = '')
36
    {
37
        $this->text = $text;
38
    }
39
40
    /**
41
     * Set the Content of the SMS message.
42
     *
43
     * @param $text
44
     *
45
     * @return $this
46
     */
47
    public function text($text)
48
    {
49
        $this->text = $text;
50
51
        return $this;
52
    }
53
54
    /**
55
     * Set the message scheduled date and time.
56
     *
57
     * @param DateTime|Carbon|int $time
58
     *
59
     * @return $this
60
     *
61
     * @throws CouldNotSendNotification
62
     */
63
    public function time($time)
64
    {
65
        if ($time instanceof DateTimeInterface) {
66
            return $this->time($time->getTimestamp());
67
        }
68
69
        if (is_numeric($time)) {
70
            $this->time = Carbon::createFromTimestamp($time);
71
72
            return $this;
73
        }
74
75
        throw CouldNotSendNotification::withErrorMessage(
76
            sprintf('Time must be a timestamp or an object implementing DateTimeInterface. %s is given', gettype($time))
77
        );
78
    }
79
80
    /**
81
     * Get the message schedule date.
82
     *
83
     * @return string
84
     */
85
    public function dateSend()
86
    {
87
        if ($this->time) {
88
            return $this->time->format('m/d/Y');
89
        }
90
    }
91
92
    /**
93
     * Get the message schedule time.
94
     *
95
     * @return string
96
     */
97
    public function timeSend()
98
    {
99
        if ($this->time) {
100
            return $this->time->format('H:i:s');
101
        }
102
    }
103
}
104