Completed
Push — master ( dc534c...acb1da )
by Kazi Mainuddin
01:14
created

MasterDriver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

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