| Total Complexity | 12 |
| Total Lines | 103 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class SnsMessage |
||
| 6 | { |
||
| 7 | const PROMOTIONAL_SMS_TYPE = 'Promotional'; |
||
| 8 | |||
| 9 | const TRANSACTIONAL_SMS_TYPE = 'Transactional'; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * The default delivery type for the SMS message. |
||
| 13 | * |
||
| 14 | * @var bool |
||
| 15 | */ |
||
| 16 | protected $promotional = true; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * The body of the message. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $body = ''; |
||
| 24 | |||
| 25 | 13 | public function __construct($content) |
|
| 26 | { |
||
| 27 | 13 | if (is_string($content)) { |
|
| 28 | 5 | $this->body($content); |
|
| 29 | } |
||
| 30 | |||
| 31 | 13 | if (is_array($content)) { |
|
| 32 | 8 | foreach ($content as $property => $value) { |
|
| 33 | 4 | if (method_exists($this, $property)) { |
|
| 34 | 4 | $this->$property($value); |
|
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | 13 | } |
|
| 39 | |||
| 40 | /** |
||
| 41 | * Creates a new instance of the message. |
||
| 42 | * |
||
| 43 | * @param array $data |
||
| 44 | * @return SnsMessage |
||
| 45 | */ |
||
| 46 | 6 | public static function create(array $data = []) |
|
| 47 | { |
||
| 48 | 6 | return new self($data); |
|
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Sets the message body. |
||
| 53 | * |
||
| 54 | * @param string $content |
||
| 55 | * @return $this |
||
| 56 | */ |
||
| 57 | 10 | public function body(string $content) |
|
| 58 | { |
||
| 59 | 10 | $this->body = trim($content); |
|
| 60 | |||
| 61 | 10 | return $this; |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get the message body. |
||
| 66 | * |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | 7 | public function getBody() |
|
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Get the SMS delivery type. |
||
| 76 | * |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | 6 | public function getDeliveryType() |
|
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Sets the SMS delivery type as promotional. |
||
| 86 | * |
||
| 87 | * @param bool $active |
||
| 88 | * @return $this |
||
| 89 | */ |
||
| 90 | 1 | public function promotional(bool $active = true) |
|
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Sets the SMS delivery type as transactional. |
||
| 99 | * |
||
| 100 | * @param bool $active |
||
| 101 | * @return $this |
||
| 102 | */ |
||
| 103 | 3 | public function transactional(bool $active = true) |
|
| 110 |