Completed
Push — master ( c675f1...96be6f )
by Hamoud
06:16 queued 10s
created

MobilyWsMessage   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

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 5
    public static function create($text = '')
26
    {
27 5
        return new static($text);
28
    }
29
30
    /**
31
     * MobilyWsMessage constructor.
32
     *
33
     * @param string $text
34
     */
35 17
    public function __construct($text = '')
36
    {
37 17
        $this->text = $text;
38 17
    }
39
40
    /**
41
     * Set the Content of the SMS message.
42
     *
43
     * @param $text
44
     *
45
     * @return $this
46
     */
47 1
    public function text($text)
48
    {
49 1
        $this->text = $text;
50
51 1
        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 6
    public function time($time)
64
    {
65 6
        if ($time instanceof DateTimeInterface) {
66 4
            return $this->time($time->getTimestamp());
67
        }
68
69 6
        if (is_numeric($time)) {
70 5
            $this->time = Carbon::createFromTimestamp($time);
71
72 5
            return $this;
73
        }
74
75 1
        throw CouldNotSendNotification::withErrorMessage(
76 1
            sprintf('Time must be a timestamp or an object implementing DateTimeInterface. %s is given', gettype($time))
77 1
        );
78
    }
79
80
    /**
81
     * Get the message schedule date.
82
     *
83
     * @return string
84
     */
85 4
    public function dateSend()
86
    {
87 4
        if ($this->time) {
88 2
            return $this->time->format('m/d/Y');
89
        }
90 2
    }
91
92
    /**
93
     * Get the message schedule time.
94
     *
95
     * @return string
96
     */
97 4
    public function timeSend()
98
    {
99 4
        if ($this->time) {
100 2
            return $this->time->format('H:i:s');
101
        }
102 2
    }
103
}
104