Completed
Pull Request — master (#13)
by
unknown
02:29
created

Driver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 0
dl 0
loc 73
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
__construct() 0 1 ?
A to() 0 15 3
A message() 0 12 3
send() 0 1 ?
1
<?php
2
namespace Tzsk\Sms\Abstracts;
3
4
use Tzsk\Sms\Contracts\DriverInterface;
5
6
abstract class Driver implements DriverInterface
7
{
8
    /**
9
     * To Numbers array.
10
     *
11
     * @var array
12
     */
13
    protected $recipients = [];
14
15
    /**
16
     * Message body.
17
     *
18
     * @var string
19
     */
20
    protected $body = "";
21
22
    /**
23
     * Driver constructor.
24
     *
25
     * @param $settings
26
     */
27
    abstract public function __construct($settings);
28
29
    /**
30
     * String or Array of numbers.
31
     *
32
     * @param $numbers string|array
33
     * @return $this
34
     * @throws \Exception
35
     */
36
    public function to($numbers)
37
    {
38
        $recipients = is_array($numbers) ? $numbers : [$numbers];
39
        $recipients = array_map(function ($item) {
40
            return trim($item);
41
        }, array_merge($this->recipients, $recipients));
42
43
        $this->recipients = array_values(array_filter($recipients));
44
45
        if (count($this->recipients) < 1) {
46
            throw new \Exception("Message recipient could not be empty.");
47
        }
48
49
        return $this;
50
    }
51
52
    /**
53
     * Set text message body.
54
     *
55
     * @param $message string
56
     * @return $this
57
     * @throws \Exception
58
     */
59
    public function message($message)
60
    {
61
        if (!is_string($message)) {
62
            throw new \Exception("Message text should be a string.");
63
        }
64
        if (trim($message) == '') {
65
            throw new \Exception("Message text could not be empty.");
66
        }
67
        $this->body = $message;
68
69
        return $this;
70
    }
71
72
    /**
73
     * Send the message
74
     *
75
     * @return object
76
     */
77
    abstract public function send();
78
}
79