Completed
Branch master (81332d)
by Kazi Mainuddin
06:43 queued 03:22
created

MasterDriver::message()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
namespace Tzsk\Sms\Drivers;
3
4
5
class MasterDriver
6
{
7
    /**
8
     * To Numbers array.
9
     *
10
     * @var array
11
     */
12
    protected $recipients = [];
13
14
    /**
15
     * Message body.
16
     *
17
     * @var null
18
     */
19
    protected $body = "";
20
21
    /**
22
     * String or Array of numbers.
23
     *
24
     * @param $numbers string|array
25
     * @return $this
26
     * @throws \Exception
27
     */
28
    public function to($numbers)
29
    {
30
        $recipients = is_array($numbers) ? $numbers : [$numbers];
31
        $recipients = array_map(function($item) {
32
            return trim($item);
33
        }, array_merge($this->recipients, $recipients));
34
35
        $this->recipients = array_values(array_filter($recipients));
36
37
        if (count($this->recipients) < 1) {
38
            throw new \Exception("Message recipient could not be empty.");
39
        }
40
41
        return $this;
42
    }
43
44
    /**
45
     * Set text message body.
46
     *
47
     * @param $message string
48
     * @return $this
49
     * @throws \Exception
50
     */
51
    public function message($message)
52
    {
53
        if (!is_string($message)) {
54
            throw new \Exception("Message text should be a string.");
55
        }
56
        if (trim($message) == '') {
57
            throw new \Exception("Message text could not be empty.");
58
        }
59
        $this->body = $message;
0 ignored issues
show
Documentation Bug introduced by
It seems like $message of type string is incompatible with the declared type null of property $body.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
61
        return $this;
62
    }
63
64
}